|
|
@ -18,20 +18,29 @@ |
|
|
|
package com.epmet.service.impl; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.epmet.commons.tools.constant.Constant; |
|
|
|
import com.epmet.commons.tools.constant.FieldConstant; |
|
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.utils.Pinyin4jUtil; |
|
|
|
import com.epmet.dao.GuideCategoryDao; |
|
|
|
import com.epmet.dto.GuideCategoryDTO; |
|
|
|
import com.epmet.dto.form.EditGuideCategoryFormDTO; |
|
|
|
import com.epmet.dto.form.GuideCateOrderFormDTO; |
|
|
|
import com.epmet.dto.form.GuideCategoryDropDownFormDTO; |
|
|
|
import com.epmet.dto.form.GuideCategoryPageFormDTO; |
|
|
|
import com.epmet.dto.result.GuideDictResDTO; |
|
|
|
import com.epmet.entity.GuideCategoryEntity; |
|
|
|
import com.epmet.service.GuideCategoryService; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
@ -45,20 +54,100 @@ import java.util.Map; |
|
|
|
public class GuideCategoryServiceImpl extends BaseServiceImpl<GuideCategoryDao, GuideCategoryEntity> implements GuideCategoryService { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 【办事指南】分类列表-工作端PC和运营端用不分页 |
|
|
|
* |
|
|
|
* @param formDTO |
|
|
|
* @return com.epmet.commons.tools.utils.Result<com.epmet.commons.tools.page.PageData<com.epmet.dto.GuideCategoryDTO>> |
|
|
|
* @author yinzuomei |
|
|
|
* @date 2021/9/8 1:33 下午 |
|
|
|
*/ |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Override |
|
|
|
public PageData<GuideCategoryDTO> page(Map<String, Object> params) { |
|
|
|
IPage<GuideCategoryEntity> page = baseDao.selectPage( |
|
|
|
getPage(params, FieldConstant.CREATED_TIME, false), |
|
|
|
getWrapper(params) |
|
|
|
); |
|
|
|
return getPageData(page, GuideCategoryDTO.class); |
|
|
|
public PageData<GuideCategoryDTO> page(GuideCategoryPageFormDTO formDTO) { |
|
|
|
List<GuideCategoryDTO> list = baseDao.selectPageByCid(formDTO.getCustomerId()); |
|
|
|
if (CollectionUtils.isEmpty(list) && !formDTO.getCustomerId().equals(Constant.DEFAULT_CUSTOMER)) { |
|
|
|
//初始化默认的给客户
|
|
|
|
initCustomerGuideCategory(formDTO.getCustomerId()); |
|
|
|
list = baseDao.selectPageByCid(formDTO.getCustomerId()); |
|
|
|
} |
|
|
|
PageInfo<GuideCategoryDTO> pageInfo = new PageInfo<>(list); |
|
|
|
return new PageData<>(list, pageInfo.getTotal()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 产品默认分类同步给客户,已经禁用的不同步 |
|
|
|
* |
|
|
|
* @param customerId |
|
|
|
* @return void |
|
|
|
* @author yinzuomei |
|
|
|
* @date 2021/9/8 2:17 下午 |
|
|
|
*/ |
|
|
|
private void initCustomerGuideCategory(String customerId) { |
|
|
|
List<GuideCategoryDTO> list = baseDao.selectPageByCid(Constant.DEFAULT_CUSTOMER); |
|
|
|
int sort = 0; |
|
|
|
for (GuideCategoryDTO dto : list) { |
|
|
|
// 已经禁用的,不同步给客户
|
|
|
|
if (Constant.DISABLE.equals(dto.getStatus())) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
dto.setCustomerId(customerId); |
|
|
|
//清空主键
|
|
|
|
dto.setId(null); |
|
|
|
dto.setSort(sort); |
|
|
|
GuideCategoryEntity entity = ConvertUtils.sourceToTarget(dto, GuideCategoryEntity.class); |
|
|
|
insert(entity); |
|
|
|
sort++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 办事指南】可用分类列表 新增、编辑指南时的下拉框:展示未禁用的分类; 查询指南列表:如果禁用的分类下存在指南列表,则展示,不存在直接不展示 |
|
|
|
* |
|
|
|
* @param formDTO |
|
|
|
* @return java.util.List<com.epmet.dto.result.GuideDictResDTO> |
|
|
|
* @author yinzuomei |
|
|
|
* @date 2021/9/8 3:06 下午 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public List<GuideCategoryDTO> list(Map<String, Object> params) { |
|
|
|
List<GuideCategoryEntity> entityList = baseDao.selectList(getWrapper(params)); |
|
|
|
public List<GuideDictResDTO> getCategory(GuideCategoryDropDownFormDTO formDTO) { |
|
|
|
List<GuideDictResDTO> list=baseDao.selectCategoryDict(formDTO.getCustomerId(),formDTO.getQueryOrigin()); |
|
|
|
if (CollectionUtils.isEmpty(list) && !formDTO.getCustomerId().equals(Constant.DEFAULT_CUSTOMER)) { |
|
|
|
//初始化默认的给客户
|
|
|
|
initCustomerGuideCategory(formDTO.getCustomerId()); |
|
|
|
list=baseDao.selectCategoryDict(formDTO.getCustomerId(),formDTO.getQueryOrigin()); |
|
|
|
} |
|
|
|
return list; |
|
|
|
} |
|
|
|
|
|
|
|
return ConvertUtils.sourceToTarget(entityList, GuideCategoryDTO.class); |
|
|
|
/** |
|
|
|
* 保存排序 |
|
|
|
* |
|
|
|
* @param formDTO |
|
|
|
* @return void |
|
|
|
* @author yinzuomei |
|
|
|
* @date 2021/9/8 4:09 下午 |
|
|
|
*/ |
|
|
|
@Transactional |
|
|
|
@Override |
|
|
|
public void saveOrder(GuideCateOrderFormDTO formDTO) { |
|
|
|
for (GuideCateOrderFormDTO.OrderIndexDTO idx : formDTO.getOrderList()) { |
|
|
|
baseDao.updateOrder(idx.getId(), idx.getOrderIndex(),formDTO.getStaffId()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 启用或者禁用分类 |
|
|
|
* |
|
|
|
* @param formDTO |
|
|
|
* @return int |
|
|
|
* @author yinzuomei |
|
|
|
* @date 2021/9/8 4:20 下午 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public void disableGuideCategory(EditGuideCategoryFormDTO formDTO) { |
|
|
|
baseDao.updateStatus(formDTO.getId(), formDTO.getStatus(),formDTO.getStaffId()); |
|
|
|
} |
|
|
|
|
|
|
|
private QueryWrapper<GuideCategoryEntity> getWrapper(Map<String, Object> params){ |
|
|
@ -70,31 +159,67 @@ public class GuideCategoryServiceImpl extends BaseServiceImpl<GuideCategoryDao, |
|
|
|
return wrapper; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public GuideCategoryDTO get(String id) { |
|
|
|
GuideCategoryEntity entity = baseDao.selectById(id); |
|
|
|
return ConvertUtils.sourceToTarget(entity, GuideCategoryDTO.class); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 新增分类,名称和编码客户内唯一 |
|
|
|
* |
|
|
|
* @param dto |
|
|
|
* @return void |
|
|
|
* @author yinzuomei |
|
|
|
* @date 2021/9/8 5:12 下午 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void save(GuideCategoryDTO dto) { |
|
|
|
GuideCategoryEntity entity = ConvertUtils.sourceToTarget(dto, GuideCategoryEntity.class); |
|
|
|
public GuideCategoryDTO save(EditGuideCategoryFormDTO dto) { |
|
|
|
if (baseDao.selectCategoryName(dto.getCategoryName().trim(), dto.getCustomerId(), null) > 0) { |
|
|
|
throw new RenException(EpmetErrorCode.GUIDE_CATEGORY_NAME_EXITS.getCode(), EpmetErrorCode.GUIDE_CATEGORY_NAME_EXITS.getMsg()); |
|
|
|
} |
|
|
|
String categoryCode = Pinyin4jUtil.getFirstSpellPinYin(dto.getCategoryName(), true); |
|
|
|
if (baseDao.selectCategoryCode(categoryCode, dto.getCustomerId(), null) > 0) { |
|
|
|
throw new RenException(EpmetErrorCode.GUIDE_CATEGORY_NAME_EXITS.getCode(), EpmetErrorCode.GUIDE_CATEGORY_NAME_EXITS.getMsg()); |
|
|
|
} |
|
|
|
GuideCategoryEntity entity = new GuideCategoryEntity(); |
|
|
|
entity.setCustomerId(dto.getCustomerId()); |
|
|
|
entity.setCategoryName(dto.getCategoryName()); |
|
|
|
entity.setCategoryCode(categoryCode); |
|
|
|
int currentMax = baseDao.selectCurrentOrder(dto.getCustomerId()); |
|
|
|
entity.setSort(currentMax == 0 ? currentMax : currentMax + 1); |
|
|
|
entity.setStatus(Constant.ENABLE); |
|
|
|
insert(entity); |
|
|
|
return ConvertUtils.sourceToTarget(entity,GuideCategoryDTO.class); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void update(GuideCategoryDTO dto) { |
|
|
|
GuideCategoryEntity entity = ConvertUtils.sourceToTarget(dto, GuideCategoryEntity.class); |
|
|
|
updateById(entity); |
|
|
|
public GuideCategoryDTO update(EditGuideCategoryFormDTO dto) { |
|
|
|
if (baseDao.selectCategoryName(dto.getCategoryName().trim(), dto.getCustomerId(), dto.getId()) > 0) { |
|
|
|
throw new RenException(EpmetErrorCode.GUIDE_CATEGORY_NAME_EXITS.getCode(), EpmetErrorCode.GUIDE_CATEGORY_NAME_EXITS.getMsg()); |
|
|
|
} |
|
|
|
|
|
|
|
String categoryCode = Pinyin4jUtil.getFirstSpellPinYin(dto.getCategoryName(), true); |
|
|
|
if (baseDao.selectCategoryCode(categoryCode, dto.getCustomerId(), dto.getId()) > 0) { |
|
|
|
throw new RenException(EpmetErrorCode.GUIDE_CATEGORY_NAME_EXITS.getCode(), EpmetErrorCode.GUIDE_CATEGORY_NAME_EXITS.getMsg()); |
|
|
|
} |
|
|
|
GuideCategoryEntity origin=baseDao.selectById(dto.getId()); |
|
|
|
origin.setCategoryCode(categoryCode); |
|
|
|
origin.setCategoryName(dto.getCategoryName()); |
|
|
|
updateById(origin); |
|
|
|
return ConvertUtils.sourceToTarget(origin,GuideCategoryDTO.class); |
|
|
|
} |
|
|
|
/** |
|
|
|
* 删除分类,存在办事指南的不允许删除,给予提示 |
|
|
|
* |
|
|
|
* @param formDTO |
|
|
|
* @return void |
|
|
|
* @author yinzuomei |
|
|
|
* @date 2021/9/8 4:34 下午 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void delete(String[] ids) { |
|
|
|
// 逻辑删除(@TableLogic 注解)
|
|
|
|
baseDao.deleteBatchIds(Arrays.asList(ids)); |
|
|
|
public void delete(EditGuideCategoryFormDTO formDTO) { |
|
|
|
// 存在指南的分类不允许删除
|
|
|
|
if(baseDao.selectGuideTotal(formDTO.getId(),formDTO.getCustomerId())>0){ |
|
|
|
throw new RenException(EpmetErrorCode.HAVE_GUIDE_CANNOT_DEL.getCode(),EpmetErrorCode.HAVE_GUIDE_CANNOT_DEL.getMsg()); |
|
|
|
} |
|
|
|
baseDao.deleteById(formDTO.getId()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |