| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- package ${basePackage}.service;
- import com.kym.common.enumeration.MsgEnum;
- import com.kym.common.exception.BizException;
- import com.kym.common.page.Res;
- import com.kym.jdbc.Bean;
- import ${basePackage}.entity.po.${pojoName};
- import ${basePackage}.entity.po.${pojoName}.${pojoName}Info;
- import ${basePackage}.entity.po.${pojoName}.${pojoName}BasicQuery;
- import org.springframework.transaction.annotation.Transactional;
- /**
- * ${pojoComment}业务类
- * @date ${datetime}
- */
- @Service("${firstLowPojoName}Service")
- public class ${pojoName}Service extends IService implements ${pojoName}Service{
- @Resource
- private ${pojoName}DAO ${firstLowPojoName}DAO;
- /**
- * ${pojoComment}分页查询
- */
- public Bean<${pojoName}Info>list(${pojoName}BasicQuery query) {
- setupQuery(query);
- return ${firstLowPojoName}DAO.selectPageBean(query);
- }
- /**
- * 查询${pojoComment}详情
- */
- public ${pojoName}Info detail(long id) {
- return ${firstLowPojoName}DAO.selectOneExist(${pojoName}Info.class,id);
- }
- /**
- * ${pojoComment}状态变更
- */
- @Transactional(rollbackFor = Exception.class)
- public void status(long id,int status) {
- ${pojoName} old = ${firstLowPojoName}DAO.selectOneExist(${pojoName}.class,id);
- ${pojoName} bean = new ${pojoName}();
- bean.setId(id);
- bean.setStatus(status);
- ${firstLowPojoName}DAO.updateSelective(bean,"status");
- super.afterModify(old,bean);
- }
- /**
- * 新增${pojoComment}
- */
- @Transactional(rollbackFor = Exception.class)
- public long add(${pojoName}Info ${firstLowPojoName}) {
- ${firstLowPojoName}DAO.checkUniqueValue(${pojoName}.class,oBuilder().eq(${pojoName}::getName, ${firstLowPojoName}.getName()),${pojoName}::getName,${firstLowPojoName}.getId());
- long ret = ${firstLowPojoName}DAO.insert(${firstLowPojoName});
- CommUtil.asserts(ret>0, MsgEnum.DB_ERROR);
- super.afterAdd(ret);
- return ret;
- }
- /**
- * 物理删除${pojoComment}
- */
- @Transactional(rollbackFor = Exception.class)
- public Res remove(long id) {
- ${firstLowPojoName}DAO.delete(${pojoName}.class,id);
- super.afterRemove(id);
- return Res.success();
- }
- /**
- * 编辑${pojoComment}
- */
- @Transactional(rollbackFor = Exception.class)
- public void modify(${pojoName}Info ${firstLowPojoName}) {
- ${pojoName}Info oldBean = ${firstLowPojoName}DAO.selectOneExist(${pojoName}Info.class, ${firstLowPojoName}.getId());
- int ret = ${firstLowPojoName}DAO.update(${firstLowPojoName});
- CommUtil.asserts(ret>0, MsgEnum.DB_ERROR);
- super.afterModify(oldBean,${firstLowPojoName});
- }
- #if(${hasCategory})
- /**
- * 新增${pojoComment}分类
- */
- @Transactional(rollbackFor = Exception.class)
- public int addCategory(${pojoName}Category category) {
- ${firstLowPojoName}DAO.checkUniqueValue(${pojoName}Category.class,oBuilder().eq(${pojoName}Category::getName, category.getName()),${pojoName}Category::getName,category.getId());
- int ret = ${firstLowPojoName}DAO.insert(category);
- CommUtil.asserts(ret>0, MsgEnum.DB_ERROR);
- super.afterAdd(ret);
- return ret;
- }
- /**
- * ${pojoComment}分类分页查询
- */
- public Res listCategory(${pojoName}Category.${pojoName}CategoryBasicQuery query) {
- return Res.succ(${firstLowPojoName}DAO.selectPageList(query));
- }
- /**
- * ${pojoComment}分类详情
- */
- public ${pojoName}Category detailCategory(long id) {
- return ${firstLowPojoName}DAO.selectOneExist(${pojoName}Category.class,id)
- }
- /**
- * ${pojoComment}分类编辑
- */
- @Transactional(rollbackFor = Exception.class)
- public void modifyCategory(${pojoName}Category category) {
- ${pojoName} old = ${firstLowPojoName}DAO.selectOneExist(${pojoName}.class,id);
- int ret =${firstLowPojoName}DAO.update(category);
- CommUtil.asserts(ret>0, MsgEnum.DB_ERROR);
- super.afterModify(old,category);
- }
- /**
- * ${pojoComment}分类发布/撤回
- */
- @Transactional(rollbackFor = Exception.class)
- public void releaseCategory(long id,int releaseStatus) {
- ${pojoName} old = ${firstLowPojoName}DAO.selectOneExist(${pojoName}.class,id);
- ${pojoName} bean = new ${pojoName}();
- bean.setId(id);
- //bean.releaseStatus = releaseStatus;
- ${firstLowPojoName}DAO.updateSelective(bean,"releaseStatus");
- super.afterModify(old,bean);
- }
- /**
- * ${pojoComment}分类物理删除
- */
- @Transactional(rollbackFor = Exception.class)
- public void removeCategory(long categoryId) {
- //子分类
- int subCategoryCount = ${firstLowPojoName}DAO.selectCount(${pojoName}Category.class, oBuilder().eq(${pojoName}Category::getPid, categoryId));
- if (subCategoryCount > 0) {
- throw new BizException(MsgEnum.SYSTEM_ERROR.code, "有子分类存在,请先删除子分类再操作");
- }
- int typeCount = ${firstLowPojoName}DAO.selectCount(${pojoName}.class,oBuilder().eq(${pojoName}.class::getCategoryId,categoryId));
- if(typeCount>0){
- throw new BizException(MsgEnum.SYSTEM_ERROR.code,"此分类下有${pojoComment},请解除分类关系或删除后再删除");
- }
- ${firstLowPojoName}DAO.delete(${pojoName}Category.class,categoryId);
- super.afterRemove(categoryId);
- }
- #end
- }
|