|
|
@ -21,6 +21,8 @@ import cn.hutool.core.collection.CollUtil; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
|
|
import com.elink.esua.epdc.commons.tools.constant.NumConstant; |
|
|
|
|
|
import com.elink.esua.epdc.commons.tools.constant.StrConstant; |
|
|
import com.elink.esua.epdc.commons.tools.page.PageData; |
|
|
import com.elink.esua.epdc.commons.tools.page.PageData; |
|
|
import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; |
|
|
import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; |
|
|
import com.elink.esua.epdc.commons.tools.constant.FieldConstant; |
|
|
import com.elink.esua.epdc.commons.tools.constant.FieldConstant; |
|
|
@ -33,6 +35,7 @@ import com.elink.esua.epdc.entity.KpiTimeLimitItemEntity; |
|
|
import com.elink.esua.epdc.feign.EventFeignClient; |
|
|
import com.elink.esua.epdc.feign.EventFeignClient; |
|
|
import com.elink.esua.epdc.redis.KpiTimeLimitItemRedis; |
|
|
import com.elink.esua.epdc.redis.KpiTimeLimitItemRedis; |
|
|
import com.elink.esua.epdc.service.KpiTimeLimitItemService; |
|
|
import com.elink.esua.epdc.service.KpiTimeLimitItemService; |
|
|
|
|
|
import com.google.common.collect.Lists; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.slf4j.LoggerFactory; |
|
|
@ -55,8 +58,6 @@ import java.util.Map; |
|
|
public class KpiTimeLimitItemServiceImpl extends BaseServiceImpl<KpiTimeLimitItemDao, KpiTimeLimitItemEntity> implements KpiTimeLimitItemService { |
|
|
public class KpiTimeLimitItemServiceImpl extends BaseServiceImpl<KpiTimeLimitItemDao, KpiTimeLimitItemEntity> implements KpiTimeLimitItemService { |
|
|
|
|
|
|
|
|
private Logger logger = LoggerFactory.getLogger(getClass()); |
|
|
private Logger logger = LoggerFactory.getLogger(getClass()); |
|
|
@Autowired |
|
|
|
|
|
private KpiTimeLimitItemRedis kpiTimeLimitItemRedis; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
private EventFeignClient eventFeignClient; |
|
|
private EventFeignClient eventFeignClient; |
|
|
@ -80,8 +81,8 @@ public class KpiTimeLimitItemServiceImpl extends BaseServiceImpl<KpiTimeLimitIte |
|
|
return ConvertUtils.sourceToTarget(entityList, KpiTimeLimitItemDTO.class); |
|
|
return ConvertUtils.sourceToTarget(entityList, KpiTimeLimitItemDTO.class); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private QueryWrapper<KpiTimeLimitItemEntity> getWrapper(Map<String, Object> params){ |
|
|
private QueryWrapper<KpiTimeLimitItemEntity> getWrapper(Map<String, Object> params) { |
|
|
String id = (String)params.get(FieldConstant.ID_HUMP); |
|
|
String id = (String) params.get(FieldConstant.ID_HUMP); |
|
|
|
|
|
|
|
|
QueryWrapper<KpiTimeLimitItemEntity> wrapper = new QueryWrapper<>(); |
|
|
QueryWrapper<KpiTimeLimitItemEntity> wrapper = new QueryWrapper<>(); |
|
|
wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); |
|
|
wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); |
|
|
@ -98,47 +99,82 @@ public class KpiTimeLimitItemServiceImpl extends BaseServiceImpl<KpiTimeLimitIte |
|
|
@Override |
|
|
@Override |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
public Result save(KpiTimeLimitItemDTO dto) { |
|
|
public Result save(KpiTimeLimitItemDTO dto) { |
|
|
for (String categoryIds : dto.getCategoryIds()) { |
|
|
List<Long[]> selectedCategoryIds = dto.getCategoryIds(); |
|
|
categoryIds = categoryIds.replaceAll("\\[", "").replaceAll("\\]", "").replace("\"", ""); |
|
|
// 用户选择的所有部门id(去重之后)
|
|
|
String[] categoryIdArray = categoryIds.split(","); |
|
|
List<Long> distinctCategoryIds = Lists.newArrayList(); |
|
|
String categoryId = categoryIdArray[categoryIdArray.length - 1]; |
|
|
|
|
|
CategoryInfoFormDTO categoryInfoFormDTO = new CategoryInfoFormDTO(); |
|
|
for (Long[] oneOptionCategoryIdArray : selectedCategoryIds) { |
|
|
Long[] ids = new Long[1]; |
|
|
for (Long categoryId : oneOptionCategoryIdArray) { |
|
|
ids[0] = Long.valueOf(categoryId); |
|
|
if (!distinctCategoryIds.contains(categoryId)) { |
|
|
categoryInfoFormDTO.setIds(ids); |
|
|
distinctCategoryIds.add(categoryId); |
|
|
Result<List<CategoryInfoResultDTO>> res = eventFeignClient.queryCategoryInfo(categoryInfoFormDTO); |
|
|
} |
|
|
if (res.getCode() != 0 || CollUtil.isEmpty(res.getData()) || res.getData().size() == 0) { |
|
|
|
|
|
return new Result().error("查询分类详情失败" + res.getMsg()); |
|
|
|
|
|
} |
|
|
} |
|
|
String allCategoryNames = ""; |
|
|
} |
|
|
String parentCategoryIds = ""; |
|
|
CategoryInfoFormDTO categoryInfoFormDto = new CategoryInfoFormDTO(); |
|
|
String parentCategoryNames = ""; |
|
|
categoryInfoFormDto.setIds(distinctCategoryIds.toArray(new Long[distinctCategoryIds.size()])); |
|
|
CategoryInfoResultDTO categoryInfoResultDTO = res.getData().get(0); |
|
|
Result<List<CategoryInfoResultDTO>> eventResult = eventFeignClient.queryCategoryInfo(categoryInfoFormDto); |
|
|
for (String parentName : categoryInfoResultDTO.getParentNames()) { |
|
|
if (!eventResult.success() || CollUtil.isEmpty(eventResult.getData())) { |
|
|
parentCategoryNames += (parentName + "-"); |
|
|
return new Result().error(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<CategoryInfoResultDTO> categoryInfoList = eventResult.getData(); |
|
|
|
|
|
|
|
|
|
|
|
KpiTimeLimitItemEntity timeLimit; |
|
|
|
|
|
List<KpiTimeLimitItemEntity> entityList = Lists.newArrayList(); |
|
|
|
|
|
|
|
|
|
|
|
for (CategoryInfoResultDTO categoryInfo : categoryInfoList) { |
|
|
|
|
|
delteTimeLimitByCategoryId(categoryInfo.getId()); |
|
|
|
|
|
|
|
|
|
|
|
timeLimit = new KpiTimeLimitItemEntity(); |
|
|
|
|
|
timeLimit.setValidCloseTime(dto.getValidCloseTime()); |
|
|
|
|
|
timeLimit.setValidRespondTime(dto.getValidRespondTime()); |
|
|
|
|
|
|
|
|
|
|
|
timeLimit.setCategoryId(categoryInfo.getId()); |
|
|
|
|
|
// 父id为根节点0,表示一级类别,不拼接根节点
|
|
|
|
|
|
if (categoryInfo.getPids().equals(NumConstant.ZERO_STR)) { |
|
|
|
|
|
timeLimit.setAllCategoryIds(String.valueOf(categoryInfo.getId())); |
|
|
|
|
|
timeLimit.setAllCategoryNames(categoryInfo.getCategoryName()); |
|
|
|
|
|
} else { |
|
|
|
|
|
timeLimit.setAllCategoryIds(categoryInfo.getPids().concat(StrConstant.COMMA).concat(String.valueOf(categoryInfo.getId()))); |
|
|
|
|
|
timeLimit.setAllCategoryNames(categoryInfo.getParentNames().concat(StrConstant.HYPHEN.concat(categoryInfo.getCategoryName()))); |
|
|
} |
|
|
} |
|
|
//去除最后一个-
|
|
|
|
|
|
parentCategoryNames = parentCategoryNames.substring(0, parentCategoryNames.length() - 1); |
|
|
timeLimit.setParentCategoryIds(categoryInfo.getPids()); |
|
|
allCategoryNames = parentCategoryNames + "-" + categoryInfoResultDTO.getCategoryName(); |
|
|
timeLimit.setParentCategoryNames(categoryInfo.getParentNames()); |
|
|
int index = categoryIds.lastIndexOf(","); |
|
|
entityList.add(timeLimit); |
|
|
// logger.info("最后一个逗号所在的位置"+index);
|
|
|
|
|
|
parentCategoryIds = categoryIds.substring(0, index); |
|
|
|
|
|
dto.setCategoryId(categoryId); |
|
|
|
|
|
dto.setAllCategoryIds(categoryIds); |
|
|
|
|
|
dto.setAllCategoryNames(allCategoryNames); |
|
|
|
|
|
dto.setParentCategoryIds(parentCategoryIds); |
|
|
|
|
|
dto.setParentCategoryNames(parentCategoryNames); |
|
|
|
|
|
KpiTimeLimitItemEntity entity = ConvertUtils.sourceToTarget(dto, KpiTimeLimitItemEntity.class); |
|
|
|
|
|
// 删除已存在的记录
|
|
|
|
|
|
QueryWrapper<KpiTimeLimitItemEntity> wrapper = new QueryWrapper<>(); |
|
|
|
|
|
wrapper.eq(StringUtils.isNotBlank(categoryId), "CATEGORY_ID", categoryId); |
|
|
|
|
|
baseDao.delete(wrapper); |
|
|
|
|
|
//插入
|
|
|
|
|
|
insert(entity); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
baseDao.deleteBatchByCategoryIds(distinctCategoryIds); |
|
|
|
|
|
this.insertBatch(entityList, NumConstant.THIRTY); |
|
|
|
|
|
|
|
|
return new Result(); |
|
|
return new Result(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 根据类别id删除类别设置 |
|
|
|
|
|
* |
|
|
|
|
|
* @param categoryId |
|
|
|
|
|
* @return int |
|
|
|
|
|
* @author work@yujt.net.cn |
|
|
|
|
|
* @date 2019/12/16 17:49 |
|
|
|
|
|
*/ |
|
|
|
|
|
private int delteTimeLimitByCategoryId(Long categoryId) { |
|
|
|
|
|
QueryWrapper<KpiTimeLimitItemEntity> wrapper = new QueryWrapper<>(); |
|
|
|
|
|
wrapper.eq("CATEGORY_ID", categoryId); |
|
|
|
|
|
return baseDao.delete(wrapper); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
|
|
List<Long> aa = Lists.newArrayList(); |
|
|
|
|
|
aa.add(0L); |
|
|
|
|
|
aa.add(1L); |
|
|
|
|
|
|
|
|
|
|
|
Long[] bb = aa.toArray(new Long[aa.size()]); |
|
|
|
|
|
for (Long aLong : bb) { |
|
|
|
|
|
System.out.println(aLong); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
public void update(KpiTimeLimitItemDTO dto) { |
|
|
public void update(KpiTimeLimitItemDTO dto) { |
|
|
|