|
@@ -1,14 +1,208 @@
|
|
|
package cn.cslg.pas.service.business;
|
|
|
|
|
|
+import cn.cslg.pas.common.dto.business.CustomFieldDTO;
|
|
|
+import cn.cslg.pas.common.dto.business.UpdateCustomFieldDTO;
|
|
|
+import cn.cslg.pas.common.model.cronModel.Personnel;
|
|
|
+import cn.cslg.pas.common.model.cronModel.PersonnelVO;
|
|
|
+import cn.cslg.pas.common.model.cronModel.Records;
|
|
|
+import cn.cslg.pas.common.model.request.GroupRequest;
|
|
|
+import cn.cslg.pas.common.model.request.QueryRequest;
|
|
|
+import cn.cslg.pas.common.utils.CacheUtils;
|
|
|
+import cn.cslg.pas.common.utils.LoginUtils;
|
|
|
+import cn.cslg.pas.common.vo.business.CustomFieldVO;
|
|
|
+import cn.cslg.pas.common.vo.business.ProductVO;
|
|
|
import cn.cslg.pas.domain.business.CustomField;
|
|
|
+import cn.cslg.pas.exception.UnLoginException;
|
|
|
+import cn.cslg.pas.exception.XiaoShiException;
|
|
|
+import cn.cslg.pas.factorys.businessFactory.Business;
|
|
|
import cn.cslg.pas.mapper.CustomFieldMapper;
|
|
|
+import cn.cslg.pas.service.permissions.PermissionService;
|
|
|
+import cn.cslg.pas.service.query.FormatQueryService;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
+ * 自定义栏位Service层
|
|
|
* @Author xiexiang
|
|
|
* @Date 2023/11/8
|
|
|
*/
|
|
|
@Service
|
|
|
-public class CustomFieldService extends ServiceImpl<CustomFieldMapper, CustomField> {
|
|
|
+public class CustomFieldService extends ServiceImpl<CustomFieldMapper, CustomField> implements Business {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CacheUtils cacheUtils;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private LoginUtils loginUtils;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FormatQueryService formatQueryService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CustomFieldMapper customFieldMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PermissionService permissionService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object queryMessage(QueryRequest queryRequest) throws Exception {
|
|
|
+ //根据专题库/报告id查询自定义栏位
|
|
|
+ List<String> sqls = formatQueryService.reSqls(queryRequest,"customField");
|
|
|
+ //根据sql查询自定义栏位信息
|
|
|
+ List<CustomFieldVO> customFieldVOS = customFieldMapper.getCustomField(sqls.get(0), sqls.get(1), sqls.get(2));
|
|
|
+ //查询总数
|
|
|
+ Long total = customFieldMapper.getCustomFieldCount(sqls.get(0));
|
|
|
+ //装载自定义栏位信息
|
|
|
+ this.loadCustomField(customFieldVOS);
|
|
|
+ //装载返回信息
|
|
|
+ Records records = new Records();
|
|
|
+ records.setCurrent(queryRequest.getCurrent());
|
|
|
+ records.setSize(queryRequest.getSize());
|
|
|
+ records.setData(customFieldVOS);
|
|
|
+ records.setTotal(total);
|
|
|
+ return records;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object addMessage(Object object, List<MultipartFile> files) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object deleteMessage(List<Integer> ids) throws IOException {
|
|
|
+ if (ids == null || ids.size() == 0) {
|
|
|
+ throw new XiaoShiException("ids不能为空");
|
|
|
+ }
|
|
|
+ this.removeBatchByIds(ids);
|
|
|
+ //TODO 删除与专题库的关联关系
|
|
|
+ return ids;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object updateMessage(Object object, List<MultipartFile> files) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object getGroup(GroupRequest groupRequest, String tableName) throws Exception {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object addMessage(Object object) {
|
|
|
+ if (object == null) {
|
|
|
+ throw new XiaoShiException("参数不能为空");
|
|
|
+ }
|
|
|
+ //object to customFieldDTO
|
|
|
+ CustomFieldDTO customFieldDTO = (CustomFieldDTO) object;
|
|
|
+ //非空校验
|
|
|
+ if (customFieldDTO.getProjectId().equals(null)) {
|
|
|
+ throw new XiaoShiException("专题库/报告id不能为空!");
|
|
|
+ }
|
|
|
+ if (customFieldDTO.getName().equals(null) || customFieldDTO.getName().equals("")) {
|
|
|
+ throw new XiaoShiException("自定义栏位名称不能为空!");
|
|
|
+ }
|
|
|
+ if (customFieldDTO.getType().equals(null)) {
|
|
|
+ throw new XiaoShiException("自定义栏位类型不能为空!");
|
|
|
+ }
|
|
|
+ String name = customFieldDTO.getName();
|
|
|
+ Integer projectId = customFieldDTO.getProjectId();
|
|
|
+ //检查名称是否规范
|
|
|
+ customFieldDTO.setName(name.trim());
|
|
|
+ //同一个专题库/报告id下名称不能重复
|
|
|
+ LambdaQueryWrapper<CustomField> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(CustomField::getName, name);
|
|
|
+ queryWrapper.eq(CustomField::getProjectId, projectId);
|
|
|
+ List<CustomField> customFields = this.list(queryWrapper);
|
|
|
+ if (customFields != null && customFields.size() != 0) {
|
|
|
+ throw new XiaoShiException("名称不能重复");
|
|
|
+ }
|
|
|
+ //获取登录人信息
|
|
|
+ PersonnelVO personnelVO = new PersonnelVO();
|
|
|
+ try {
|
|
|
+ personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new UnLoginException("未登录");
|
|
|
+ }
|
|
|
+ CustomField customField = new CustomField();
|
|
|
+ BeanUtils.copyProperties(customFieldDTO, customField);
|
|
|
+ customField.setCreateId(personnelVO.getId());
|
|
|
+ customField.insert();
|
|
|
+ return customField.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object updateMessage(Object object) {
|
|
|
+ if (object == null) {
|
|
|
+ throw new XiaoShiException("参数不能为空");
|
|
|
+ }
|
|
|
+ //object to updateCustomFieldDTO
|
|
|
+ UpdateCustomFieldDTO updateCustomFieldDTO = (UpdateCustomFieldDTO) object;
|
|
|
+ //非空校验
|
|
|
+ if (updateCustomFieldDTO.getProjectId().equals(null)) {
|
|
|
+ throw new XiaoShiException("专题库/报告id不能为空!");
|
|
|
+ }
|
|
|
+ if (updateCustomFieldDTO.getName().equals(null) || updateCustomFieldDTO.getName().equals("")) {
|
|
|
+ throw new XiaoShiException("自定义栏位名称不能为空!");
|
|
|
+ }
|
|
|
+ if (updateCustomFieldDTO.getType().equals(null)) {
|
|
|
+ throw new XiaoShiException("自定义栏位类型不能为空!");
|
|
|
+ }
|
|
|
+ String name = updateCustomFieldDTO.getName();
|
|
|
+ Integer projectId = updateCustomFieldDTO.getProjectId();
|
|
|
+ CustomField customField = this.getById(updateCustomFieldDTO.getId());
|
|
|
+ //检查名称是否规范
|
|
|
+ updateCustomFieldDTO.setName(name.trim());
|
|
|
+ //同一个专题库/报告id下名称不能重复
|
|
|
+ LambdaQueryWrapper<CustomField> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(CustomField::getName, name);
|
|
|
+ queryWrapper.eq(CustomField::getProjectId, projectId);
|
|
|
+ List<CustomField> customFields = this.list(queryWrapper);
|
|
|
+ if (!name.equals(customField.getName()) && customFields.size() != 0) {
|
|
|
+ throw new XiaoShiException("名称重复");
|
|
|
+ }
|
|
|
+ BeanUtils.copyProperties(updateCustomFieldDTO, customField);
|
|
|
+ customField.updateById();
|
|
|
+ return customField.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 装载自定义栏位
|
|
|
+ * @param customFieldVOS
|
|
|
+ */
|
|
|
+ private void loadCustomField(List<CustomFieldVO> customFieldVOS) throws IOException {
|
|
|
+ List<String> createIds = new ArrayList<>();
|
|
|
+ customFieldVOS.forEach(
|
|
|
+ item -> {
|
|
|
+ if (item.getCreateId() != null) {
|
|
|
+ createIds.add(item.getCreateId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ List<Personnel> personnels = new ArrayList<>();
|
|
|
+ //查询创建人名称
|
|
|
+ if (createIds.size() != 0) {
|
|
|
+ String res = permissionService.getPersonnelByIdsFromPCS(createIds);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
+ personnels = JSONObject.parseArray(jsonObject.getString("data"), Personnel.class);
|
|
|
+ }
|
|
|
+ for (CustomFieldVO customFieldVO : customFieldVOS) {
|
|
|
+ //装载人员信息
|
|
|
+ Personnel personnel = personnels.stream().filter(item -> item.getId().equals(customFieldVO.getCreateId())).findFirst().orElse(null);
|
|
|
+ if (personnel != null) {
|
|
|
+ customFieldVO.setCreateName(personnel.getPersonnelName());
|
|
|
+ } else {
|
|
|
+ throw new XiaoShiException("未获取到当前登陆人信息");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|