|
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
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.baomidou.mybatisplus.core.toolkit.StringUtils; |
|
|
|
import com.hnac.hzims.safeproduct.dto.CheckCompanyDTO; |
|
|
|
import com.hnac.hzims.safeproduct.dto.CheckCompanyDTO; |
|
|
|
import com.hnac.hzims.safeproduct.entity.CheckCompanyEntity; |
|
|
|
import com.hnac.hzims.safeproduct.entity.CheckCompanyEntity; |
|
|
|
import com.hnac.hzims.safeproduct.entity.CheckItemEntity; |
|
|
|
import com.hnac.hzims.safeproduct.entity.CheckItemEntity; |
|
|
@ -15,7 +16,9 @@ import com.hnac.hzims.safeproduct.vo.CheckCompanyVo; |
|
|
|
import com.hnac.hzims.safeproduct.wrapper.CheckCompanyWrapper; |
|
|
|
import com.hnac.hzims.safeproduct.wrapper.CheckCompanyWrapper; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
|
|
import org.springblade.core.mp.base.BaseEntity; |
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl; |
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl; |
|
|
|
|
|
|
|
import org.springblade.core.mp.support.BladePage; |
|
|
|
import org.springblade.core.mp.support.Condition; |
|
|
|
import org.springblade.core.mp.support.Condition; |
|
|
|
import org.springblade.core.mp.support.Query; |
|
|
|
import org.springblade.core.mp.support.Query; |
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
import org.springblade.core.tool.api.R; |
|
|
@ -37,112 +40,117 @@ import java.util.stream.Collectors; |
|
|
|
@Slf4j |
|
|
|
@Slf4j |
|
|
|
public class CheckCompanyServiceImpl extends BaseServiceImpl<CheckCompanyMapper, CheckCompanyEntity> implements ICheckCompanyService { |
|
|
|
public class CheckCompanyServiceImpl extends BaseServiceImpl<CheckCompanyMapper, CheckCompanyEntity> implements ICheckCompanyService { |
|
|
|
|
|
|
|
|
|
|
|
private final CheckCompanyMapper CheckCompanyMapper; |
|
|
|
private final CheckCompanyMapper CheckCompanyMapper; |
|
|
|
|
|
|
|
|
|
|
|
private final ICheckItemInstanceService itemInstanceService; |
|
|
|
private final ICheckItemInstanceService itemInstanceService; |
|
|
|
|
|
|
|
|
|
|
|
private final ISysClient sysClient; |
|
|
|
private final ISysClient sysClient; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean doSave(CheckCompanyDTO req) { |
|
|
|
public boolean doSave(CheckCompanyDTO req) { |
|
|
|
boolean result = save(req); |
|
|
|
boolean result = save(req); |
|
|
|
if (result) { |
|
|
|
if (result) { |
|
|
|
Long checkId = req.getId(); |
|
|
|
Long checkId = req.getId(); |
|
|
|
List<CheckItemInstanceEntity> items = req.getItems(); |
|
|
|
List<CheckItemInstanceEntity> items = req.getItems(); |
|
|
|
items.forEach(item -> { |
|
|
|
items.forEach(item -> { |
|
|
|
item.setOid(item.getId()); |
|
|
|
item.setOid(item.getId()); |
|
|
|
item.setId(null); |
|
|
|
item.setId(null); |
|
|
|
item.setCheckId(checkId); |
|
|
|
item.setCheckId(checkId); |
|
|
|
}); |
|
|
|
}); |
|
|
|
itemInstanceService.saveBatch(items); |
|
|
|
itemInstanceService.saveBatch(items); |
|
|
|
} |
|
|
|
} |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean doUpdate(CheckCompanyDTO req) { |
|
|
|
public boolean doUpdate(CheckCompanyDTO req) { |
|
|
|
boolean result = updateById(req); |
|
|
|
boolean result = updateById(req); |
|
|
|
if (result) { |
|
|
|
if (result) { |
|
|
|
List<CheckItemInstanceEntity> items = req.getItems(); |
|
|
|
List<CheckItemInstanceEntity> items = req.getItems(); |
|
|
|
items.forEach(itemInstanceService::updateById); |
|
|
|
items.forEach(itemInstanceService::updateById); |
|
|
|
} |
|
|
|
} |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public R<CheckCompanyVo> detail(Long id) { |
|
|
|
public R<CheckCompanyVo> detail(Long id) { |
|
|
|
CheckCompanyEntity entity = CheckCompanyMapper.selectById(id); |
|
|
|
CheckCompanyEntity entity = CheckCompanyMapper.selectById(id); |
|
|
|
CheckCompanyVo vo = CheckCompanyWrapper.build().entityVO(entity); |
|
|
|
CheckCompanyVo vo = CheckCompanyWrapper.build().entityVO(entity); |
|
|
|
//查询检查项
|
|
|
|
//查询检查项
|
|
|
|
QueryWrapper<CheckItemInstanceEntity> queryMapper = new QueryWrapper<>(); |
|
|
|
QueryWrapper<CheckItemInstanceEntity> queryMapper = new QueryWrapper<>(); |
|
|
|
queryMapper.eq("CHECK_ID", vo.getId()); |
|
|
|
queryMapper.eq("CHECK_ID", vo.getId()); |
|
|
|
queryMapper.orderByAsc("ORG_ID", "SORT"); |
|
|
|
queryMapper.orderByAsc("ORG_ID", "SORT"); |
|
|
|
List<CheckItemInstanceEntity> items = itemInstanceService.list(queryMapper); |
|
|
|
List<CheckItemInstanceEntity> items = itemInstanceService.list(queryMapper); |
|
|
|
//查询子项,用于前端判断
|
|
|
|
//查询子项,用于前端判断
|
|
|
|
items.forEach(item -> item.setChildren(findChildren(item, items))); |
|
|
|
items.forEach(item -> item.setChildren(findChildren(item, items))); |
|
|
|
//按部门分组
|
|
|
|
//按部门分组
|
|
|
|
List<Map<String, Object>> list = new ArrayList<>(); |
|
|
|
List<Map<String, Object>> list = new ArrayList<>(); |
|
|
|
Map<Long, List<CheckItemInstanceEntity>> map = items.stream().collect(Collectors.groupingBy(CheckItemInstanceEntity::getOrgId)); |
|
|
|
Map<Long, List<CheckItemInstanceEntity>> map = items.stream().collect(Collectors.groupingBy(CheckItemInstanceEntity::getOrgId)); |
|
|
|
for (Map.Entry<Long, List<CheckItemInstanceEntity>> entry : map.entrySet()) { |
|
|
|
for (Map.Entry<Long, List<CheckItemInstanceEntity>> entry : map.entrySet()) { |
|
|
|
Map<String, Object> data = new HashMap<>(); |
|
|
|
Map<String, Object> data = new HashMap<>(); |
|
|
|
data.put("deptId", entry.getKey()); |
|
|
|
data.put("deptId", entry.getKey()); |
|
|
|
R<Dept> deptR = sysClient.getDept(entry.getKey()); |
|
|
|
R<Dept> deptR = sysClient.getDept(entry.getKey()); |
|
|
|
if (deptR.isSuccess()) { |
|
|
|
if (deptR.isSuccess()) { |
|
|
|
data.put("deptName", Optional.ofNullable(deptR.getData()).map(Dept::getDeptName).orElse(null)); |
|
|
|
data.put("deptName", Optional.ofNullable(deptR.getData()).map(Dept::getDeptName).orElse(null)); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
data.put("deptName", null); |
|
|
|
data.put("deptName", null); |
|
|
|
} |
|
|
|
} |
|
|
|
data.put("items", entry.getValue()); |
|
|
|
data.put("items", entry.getValue()); |
|
|
|
list.add(data); |
|
|
|
list.add(data); |
|
|
|
} |
|
|
|
} |
|
|
|
vo.setItems(list); |
|
|
|
vo.setItems(list); |
|
|
|
return R.data(vo); |
|
|
|
return R.data(vo); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<CheckItemEntity> findChildren(CheckItemInstanceEntity entity, List<CheckItemInstanceEntity> list) { |
|
|
|
private List<CheckItemEntity> findChildren(CheckItemInstanceEntity entity, List<CheckItemInstanceEntity> list) { |
|
|
|
List<CheckItemEntity> child = new ArrayList<>(); |
|
|
|
List<CheckItemEntity> child = new ArrayList<>(); |
|
|
|
for (CheckItemInstanceEntity itemEntity : list) { |
|
|
|
for (CheckItemInstanceEntity itemEntity : list) { |
|
|
|
if (null != itemEntity.getParentItem() |
|
|
|
if (null != itemEntity.getParentItem() |
|
|
|
&& itemEntity.getParentItem().equals(entity.getOid()) |
|
|
|
&& itemEntity.getParentItem().equals(entity.getOid()) |
|
|
|
&& itemEntity.getOrgId().equals(entity.getOrgId())) { |
|
|
|
&& itemEntity.getOrgId().equals(entity.getOrgId())) { |
|
|
|
child.add(itemEntity); |
|
|
|
child.add(itemEntity); |
|
|
|
itemEntity.setChildren(findChildren(itemEntity, list)); |
|
|
|
itemEntity.setChildren(findChildren(itemEntity, list)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return child; |
|
|
|
return child; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean doDelete(String ids) { |
|
|
|
public boolean doDelete(String ids) { |
|
|
|
List<Long> list = Func.toLongList(ids); |
|
|
|
List<Long> list = Func.toLongList(ids); |
|
|
|
boolean result = deleteLogic(list); |
|
|
|
boolean result = deleteLogic(list); |
|
|
|
if (result) { |
|
|
|
if (result) { |
|
|
|
list.forEach(id -> { |
|
|
|
list.forEach(id -> { |
|
|
|
QueryWrapper<CheckItemInstanceEntity> queryMapper = new QueryWrapper<>(); |
|
|
|
QueryWrapper<CheckItemInstanceEntity> queryMapper = new QueryWrapper<>(); |
|
|
|
queryMapper.eq("CHECK_ID", id); |
|
|
|
queryMapper.eq("CHECK_ID", id); |
|
|
|
itemInstanceService.remove(queryMapper); |
|
|
|
itemInstanceService.remove(queryMapper); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public R<IPage<CheckCompanyVo>> pageCondition(CheckCompanyEntity req, Query query) { |
|
|
|
public R<BladePage<CheckCompanyVo>> pageCondition(CheckCompanyEntity req, Query query) { |
|
|
|
Wrapper<CheckCompanyEntity> queryWrapper = new LambdaQueryWrapper<CheckCompanyEntity>() {{ |
|
|
|
Wrapper<CheckCompanyEntity> queryWrapper = new LambdaQueryWrapper<CheckCompanyEntity>() {{ |
|
|
|
orderByDesc(CheckCompanyEntity::getCreateTime); |
|
|
|
orderByDesc(CheckCompanyEntity::getCreateTime); |
|
|
|
if (ObjectUtil.isNotEmpty(req.getStartTime())) { |
|
|
|
if (ObjectUtil.isNotEmpty(req.getStartTime())) { |
|
|
|
ge(CheckCompanyEntity::getStartTime, req.getStartTime()); |
|
|
|
ge(CheckCompanyEntity::getStartTime, req.getStartTime()); |
|
|
|
} |
|
|
|
} |
|
|
|
if (ObjectUtil.isNotEmpty(req.getEndTime())) { |
|
|
|
if (ObjectUtil.isNotEmpty(req.getEndTime())) { |
|
|
|
le(CheckCompanyEntity::getEndTime, req.getEndTime()); |
|
|
|
le(CheckCompanyEntity::getEndTime, req.getEndTime()); |
|
|
|
} |
|
|
|
} |
|
|
|
if (ObjectUtil.isNotEmpty(req.getStatus())) { |
|
|
|
if (ObjectUtil.isNotEmpty(req.getStatus())) { |
|
|
|
eq(CheckCompanyEntity::getStatus, req.getStatus()); |
|
|
|
eq(CheckCompanyEntity::getStatus, req.getStatus()); |
|
|
|
} |
|
|
|
} |
|
|
|
}}; |
|
|
|
eq(StringUtils.isNotBlank(req.getAreaId()), BaseEntity::getCreateDept, req.getAreaId()); |
|
|
|
IPage page = page(Condition.getPage(query), queryWrapper); |
|
|
|
apply(req.getYearMonth() != null, "date_format(start_time ,'%Y-%m') = '" |
|
|
|
page.setRecords(CheckCompanyWrapper.build().listVO(page.getRecords())); |
|
|
|
+ req.getYearMonth() + "'" + "and date_format(end_time,'%Y-%m') = '" + req.getYearMonth() + "'"); |
|
|
|
return R.data(page); |
|
|
|
|
|
|
|
} |
|
|
|
}}; |
|
|
|
|
|
|
|
IPage page = page(Condition.getPage(query), queryWrapper); |
|
|
|
|
|
|
|
page.setRecords(CheckCompanyWrapper.build().listVO(page.getRecords())); |
|
|
|
|
|
|
|
BladePage bladePage = BladePage.of(page); |
|
|
|
|
|
|
|
return R.data(bladePage); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|