|
@@ -0,0 +1,164 @@
|
|
|
+package cn.cslg.pas.service.report;
|
|
|
+
|
|
|
+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.report.QueryIprPersonDTO;
|
|
|
+import cn.cslg.pas.common.model.report.QueryIprPersonVO;
|
|
|
+import cn.cslg.pas.common.model.report.UpdateIprPersonDTO;
|
|
|
+import cn.cslg.pas.common.utils.CacheUtils;
|
|
|
+import cn.cslg.pas.common.utils.LoginUtils;
|
|
|
+import cn.cslg.pas.exception.ExceptionEnum;
|
|
|
+import cn.cslg.pas.exception.XiaoShiException;
|
|
|
+import cn.cslg.pas.service.permissions.PermissionService;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import cn.cslg.pas.domain.report.IprPerson;
|
|
|
+import cn.cslg.pas.mapper.report.IprPersonMapper;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+
|
|
|
+import javax.transaction.xa.XAException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author admin
|
|
|
+ * @description 针对表【ipr_person(IPR人员)】的数据库操作Service实现
|
|
|
+ * @createDate 2024-12-24 13:52:34
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class IprPersonService extends ServiceImpl<IprPersonMapper, IprPerson> {
|
|
|
+ private final LoginUtils loginUtils;
|
|
|
+ private final CacheUtils cacheUtils;
|
|
|
+ private final PermissionService permissionService;
|
|
|
+
|
|
|
+ public Integer updateIprPerson(UpdateIprPersonDTO updateIprPersonDTO) {
|
|
|
+ Integer id = updateIprPersonDTO.getId();
|
|
|
+ IprPerson iprPerson = new IprPerson();
|
|
|
+ if (id == null) {
|
|
|
+ iprPerson = this.addIprPersonDB(updateIprPersonDTO);
|
|
|
+ } else {
|
|
|
+ iprPerson = this.updateIprPersonDB(updateIprPersonDTO);
|
|
|
+ }
|
|
|
+ return iprPerson.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ public IprPerson addIprPersonDB(UpdateIprPersonDTO updateIprPersonDTO) {
|
|
|
+ PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
|
|
|
+ String personId = personnelVO.getId();
|
|
|
+ Integer tenantId = personnelVO.getTenantId();
|
|
|
+ IprPerson iprPerson = new IprPerson();
|
|
|
+ BeanUtils.copyProperties(updateIprPersonDTO, iprPerson);
|
|
|
+ iprPerson.setCreateId(personId);
|
|
|
+ iprPerson.setTenantId(tenantId);
|
|
|
+ iprPerson.setId(null);
|
|
|
+ iprPerson.insert();
|
|
|
+ return iprPerson;
|
|
|
+ }
|
|
|
+
|
|
|
+ public IprPerson updateIprPersonDB(UpdateIprPersonDTO updateIprPersonDTO) {
|
|
|
+ Integer id = updateIprPersonDTO.getId();
|
|
|
+ IprPerson iprPerson = this.getById(id);
|
|
|
+ if (iprPerson == null) {
|
|
|
+ throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR, "ipr人员不存在");
|
|
|
+ }
|
|
|
+ iprPerson.setName(updateIprPersonDTO.getName());
|
|
|
+ iprPerson.setEmail(updateIprPersonDTO.getEmail());
|
|
|
+ iprPerson.setIfDefault(updateIprPersonDTO.getIfDefault());
|
|
|
+ iprPerson.updateById();
|
|
|
+ return iprPerson;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public List<Integer> delete(List<Integer> ids) {
|
|
|
+ if (ids == null || ids.size() == 0) {
|
|
|
+ throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR, "请选择至少一条数据进行删除");
|
|
|
+ }
|
|
|
+ this.removeBatchByIds(ids);
|
|
|
+ return ids;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public Records query(QueryIprPersonDTO queryIprPersonDTO) {
|
|
|
+ Records records = new Records();
|
|
|
+ List<IprPerson> iprPersonList = new ArrayList<>();
|
|
|
+ String name = queryIprPersonDTO.getName();
|
|
|
+ String email = queryIprPersonDTO.getEmail();
|
|
|
+ Boolean ifDefault = queryIprPersonDTO.getIfDefault();
|
|
|
+ Long current = queryIprPersonDTO.getCurrent();
|
|
|
+ Long size = queryIprPersonDTO.getSize();
|
|
|
+ records.setCurrent(current);
|
|
|
+ records.setSize(size);
|
|
|
+
|
|
|
+ PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
|
|
|
+ Integer tenantId = personnelVO.getTenantId();
|
|
|
+ LambdaQueryWrapper<IprPerson> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(IprPerson::getTenantId, tenantId);
|
|
|
+ if (name != null && !name.trim().equals("")) {
|
|
|
+ queryWrapper.like(IprPerson::getName, name);
|
|
|
+ }
|
|
|
+ if (email != null && !email.trim().equals("")) {
|
|
|
+ queryWrapper.like(IprPerson::getEmail, email);
|
|
|
+ }
|
|
|
+ if (ifDefault != null) {
|
|
|
+ queryWrapper.eq(IprPerson::getIfDefault, ifDefault);
|
|
|
+ }
|
|
|
+ queryWrapper.orderByDesc(IprPerson::getCreateTime);
|
|
|
+
|
|
|
+ if (current != null && size != null) {
|
|
|
+ IPage<IprPerson> iprPersonIPage = this.page(new Page<>(current, size), queryWrapper);
|
|
|
+ Long total = iprPersonIPage.getTotal();
|
|
|
+ iprPersonList = iprPersonIPage.getRecords();
|
|
|
+ records.setData(iprPersonList);
|
|
|
+ records.setTotal(total);
|
|
|
+ } else {
|
|
|
+ iprPersonList = this.list(queryWrapper);
|
|
|
+ }
|
|
|
+ List<QueryIprPersonVO> queryIprPersonVOS = this.loadQueryIprPersonVO(iprPersonList);
|
|
|
+ records.setData(queryIprPersonVOS);
|
|
|
+ return records;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<QueryIprPersonVO> loadQueryIprPersonVO(List<IprPerson> iprPersonList) {
|
|
|
+ List<QueryIprPersonVO> queryIprPersonVOS = new ArrayList<>();
|
|
|
+ if (iprPersonList == null || iprPersonList.size() == 0) {
|
|
|
+ return queryIprPersonVOS;
|
|
|
+ }
|
|
|
+ List<Personnel> personnels = new ArrayList<>();
|
|
|
+ List<String> createIds = iprPersonList.stream().map(IprPerson::getCreateId).collect(Collectors.toList());
|
|
|
+ if (!CollectionUtils.isEmpty(createIds)) {
|
|
|
+ try {
|
|
|
+ String res = permissionService.getPersonnelByIdsFromPCS(createIds);
|
|
|
+ JSONObject jsonObject = JSON.parseObject(res);
|
|
|
+ personnels = JSONObject.parseArray(jsonObject.getString("data"), Personnel.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for (IprPerson iprPerson : iprPersonList) {
|
|
|
+ QueryIprPersonVO queryIprPersonVO = new QueryIprPersonVO();
|
|
|
+ BeanUtils.copyProperties(iprPerson, queryIprPersonVO);
|
|
|
+ Personnel personnel = personnels.stream().filter(item -> item.getId().equals(iprPerson.getCreateId())).findFirst().orElse(null);
|
|
|
+ if (personnel != null) {
|
|
|
+ queryIprPersonVO.setCreateName(personnel.getPersonnelName());
|
|
|
+ }
|
|
|
+ queryIprPersonVOS.add(queryIprPersonVO);
|
|
|
+ }
|
|
|
+ return queryIprPersonVOS;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|