add 功能安全中心查询,新增成员单位

This commit is contained in:
lijiarao
2024-07-01 16:22:02 +08:00
parent 2f4fb76d2b
commit 5b3a6c6275
4 changed files with 114 additions and 1 deletions
+2
View File
@@ -59,3 +59,5 @@ create table pay_functional_safety_center_subitem_contacts
alter table pay_functional_safety_center_subitem_contacts
add primary key (id);
insert into sys_dict_item (id, dict_id, item_text, item_value, description, sort_order, status, create_by, create_time, update_by, update_time)
values ('1803314563741982722', '1432280766382727169', '功能安全中心会议', '9', '', 9.00, 1, 'LKGLZ', '2024-06-19 14:31:11', 'LKGLZ', '2024-06-25 10:40:33');
@@ -52,7 +52,7 @@ public class SafetyCenterSubitemController extends JeroController<SafetyCenterSu
HttpServletRequest req) {
QueryWrapper<SafetyCenterSubitem> queryWrapper = QueryGenerator.initQueryWrapper(safetyCenterSubitem, req.getParameterMap());
Page<SafetyCenterSubitem> page = new Page<>(pageNo, pageSize);
IPage<SafetyCenterSubitem> pageList = safetyCenterSubitemService.page(page, queryWrapper);
IPage<SafetyCenterSubitem> pageList = safetyCenterSubitemService.pageList(page, queryWrapper);
return Result.OK(pageList);
}
@@ -4,10 +4,16 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.jero.common.aspect.annotation.Dict;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.Date;
import java.util.List;
import lombok.Data;
import org.jeecgframework.poi.excel.annotation.Excel;
import javax.validation.constraints.Size;
/**
*功能安全中心成员
@@ -37,8 +43,21 @@ public class SafetyCenterSubitem {
*/
@TableField(value = "company_id")
@ApiModelProperty(value = "成员单位id")
@Excel(name = "成员单位", width = 15, dictTable = "pay_company_management", dicText = "company_name", dicCode = "id")
@Dict(dictTable = "pay_company_management", dicText = "company_name", dicCode = "id")
private String companyId;
/**企业联系人id*/
@TableField(exist = false)
@ApiModelProperty(value = "企业联系人id")
@Dict(dictTable = "pay_contacts_management", dicText = "name", dicCode = "id")
private String contactsId;
/**企业联系人列表*/
@TableField(exist = false)
@ApiModelProperty(value = "企业联系人列表")
private List<SafetyCenterSubitemContacts> contactsList;
/**
* 备注
*/
@@ -1,11 +1,25 @@
package com.jero.functionalsafetycenter.service;
import cn.hutool.core.collection.CollStreamUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jero.common.exception.JeroBootException;
import com.jero.functionalsafetycenter.entity.SafetyCenter;
import com.jero.functionalsafetycenter.entity.SafetyCenterSubitemContacts;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jero.functionalsafetycenter.mapper.SafetyCenterSubitemMapper;
import com.jero.functionalsafetycenter.entity.SafetyCenterSubitem;
import javax.annotation.Resource;
/**
*
*@author liJiaRao
@@ -13,12 +27,67 @@ import com.jero.functionalsafetycenter.entity.SafetyCenterSubitem;
*/
@Service
public class SafetyCenterSubitemService extends ServiceImpl<SafetyCenterSubitemMapper, SafetyCenterSubitem> {
@Resource
private SafetyCenterService safetyCenterService;
@Resource
private SafetyCenterSubitemContactsService contactsService;
public void add(SafetyCenterSubitem safetyCenterSubitem) {
String projectId = safetyCenterSubitem.getProjectId();
SafetyCenter safetyCenter = safetyCenterService.getById(projectId);
if (safetyCenter == null){
throw new JeroBootException("项目不存在");
}
//判重,公司是否重复
String companyId = safetyCenterSubitem.getCompanyId();
LambdaQueryWrapper<SafetyCenterSubitem> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(SafetyCenterSubitem::getProjectId,projectId);
wrapper.eq(SafetyCenterSubitem::getCompanyId,companyId);
if (this.count(wrapper) > 0){
throw new JeroBootException("成员单位已经存在");
}
this.save(safetyCenterSubitem);
//保存成员单位联系人
String subitemId = safetyCenterSubitem.getId();
List<SafetyCenterSubitemContacts> contactsList = safetyCenterSubitem.getContactsList();
for (SafetyCenterSubitemContacts contacts : contactsList) {
contacts.setProjectId(projectId);
contacts.setCompanyId(companyId);
contacts.setSubitemId(subitemId);
}
contactsService.saveBatch(contactsList);
}
public void editById(SafetyCenterSubitem safetyCenterSubitem) {
String subitemId = safetyCenterSubitem.getId();
String projectId = safetyCenterSubitem.getProjectId();
SafetyCenter safetyCenter = safetyCenterService.getById(projectId);
if (safetyCenter == null){
throw new JeroBootException("项目不存在");
}
//判重,公司是否重复
String companyId = safetyCenterSubitem.getCompanyId();
LambdaQueryWrapper<SafetyCenterSubitem> wrapper = new LambdaQueryWrapper<>();
wrapper.ne(SafetyCenterSubitem::getId,subitemId);
wrapper.eq(SafetyCenterSubitem::getProjectId,projectId);
wrapper.eq(SafetyCenterSubitem::getCompanyId,companyId);
if (this.count(wrapper) > 0){
throw new JeroBootException("成员单位已经存在");
}
this.updateById(safetyCenterSubitem);
//先删除之前保存的
LambdaQueryWrapper<SafetyCenterSubitemContacts> wrapper1 = new LambdaQueryWrapper<>();
wrapper1.eq(SafetyCenterSubitemContacts::getSubitemId,subitemId);
contactsService.remove(wrapper1);
//保存成员单位联系人
List<SafetyCenterSubitemContacts> contactsList = safetyCenterSubitem.getContactsList();
for (SafetyCenterSubitemContacts contacts : contactsList) {
contacts.setProjectId(projectId);
contacts.setCompanyId(companyId);
contacts.setSubitemId(subitemId);
}
contactsService.saveBatch(contactsList);
}
public void deleteById(String id) {
@@ -35,4 +104,27 @@ public class SafetyCenterSubitemService extends ServiceImpl<SafetyCenterSubitemM
SafetyCenterSubitem safetyCenterSubitem = this.getById(id);
return safetyCenterSubitem;
}
public IPage<SafetyCenterSubitem> pageList(Page<SafetyCenterSubitem> page, QueryWrapper<SafetyCenterSubitem> queryWrapper) {
IPage<SafetyCenterSubitem> pageList = this.page(page, queryWrapper);
List<SafetyCenterSubitem> records = pageList.getRecords();
//根据企业id获取所有联系人
List<String> companyIdList = records.stream().map(SafetyCenterSubitem::getCompanyId).collect(Collectors.toList());
LambdaQueryWrapper<SafetyCenterSubitemContacts> wrapper = new LambdaQueryWrapper<>();
wrapper.in(SafetyCenterSubitemContacts::getCompanyId,companyIdList);
wrapper.orderByAsc(SafetyCenterSubitemContacts::getCompanyId);
//根据orderNum排序
wrapper.orderByAsc(SafetyCenterSubitemContacts::getOrderNum);
List<SafetyCenterSubitemContacts> contactsList = contactsService.list(wrapper);
//根据企业id分组
Map<String, List<SafetyCenterSubitemContacts>> stringListMap = CollStreamUtil.groupByKey(contactsList, SafetyCenterSubitemContacts::getCompanyId);
//遍历,存入数据
for (SafetyCenterSubitem subitem : records) {
String companyId = subitem.getCompanyId();
List<SafetyCenterSubitemContacts> safetyCenterSubitemContacts = stringListMap.get(companyId);
subitem.setContactsId(safetyCenterSubitemContacts.get(0).getContactsId());
subitem.setContactsList(safetyCenterSubitemContacts);
}
return pageList;
}
}