Commit da2fd0e2 authored by 竹天卫's avatar 竹天卫

产值功能

parent dad5859d
package cn.wise.sc.cement.business.controller;
import cn.wise.sc.cement.business.entity.NonStandardApply;
import cn.wise.sc.cement.business.model.BaseResponse;
import cn.wise.sc.cement.business.model.PageQuery;
import cn.wise.sc.cement.business.model.query.NonStandardApplyQuery;
......
......@@ -40,10 +40,9 @@ public class NonStandardValueController {
@Autowired
private INonStandardValueService inonStandardValueService;
@ApiOperation(value = "非标产值分页")
@GetMapping("/getPage")
public BaseResponse getPage(PageQuery pageQuery, Integer userId, String name,String start, String end) {
try {
@GetMapping("/user_id")
@ApiOperation("产值统计-非标产值")
public BaseResponse nonValue(PageQuery pageQuery, String start, String end, Integer groups,String name) {
Date startParse = null;
if (StrUtil.isNotBlank(start)) {
startParse = DateUtil.parse(start);
......@@ -52,16 +51,20 @@ public class NonStandardValueController {
if (StrUtil.isNotBlank(end)) {
endParse = DateUtil.parse(end);
}
return inonStandardValueService.getPage(pageQuery, userId, name,startParse,endParse);
} catch (Exception e) {
log.debug("非标产值分页列表{}", e);
//将list拆分成分页
BaseResponse<List<NonStandardValue>> baseResponse = inonStandardValueService.nonValue(startParse, endParse, groups,name);
List<NonStandardValue> data = baseResponse.getData();
if (data.size() != 0) {
Page<NonStandardValue> rts = PageUtil.listConvertToPage(data, pageQuery);
return BaseResponse.okData(rts);
}
return BaseResponse.errorMsg("失败!");
return baseResponse;
}
@GetMapping("/user_id")
@ApiOperation("非标产值统计")
public BaseResponse nonValue(PageQuery pageQuery, String start, String end, Integer groups,String name) {
@ApiOperation(value = "产值统计-非标产值-产看明细")
@GetMapping("/getPage")
public BaseResponse getPage(PageQuery pageQuery, Integer userId, String name,String start, String end) {
try {
Date startParse = null;
if (StrUtil.isNotBlank(start)) {
startParse = DateUtil.parse(start);
......@@ -70,14 +73,11 @@ public class NonStandardValueController {
if (StrUtil.isNotBlank(end)) {
endParse = DateUtil.parse(end);
}
//将list拆分成分页
BaseResponse<List<NonStandardValue>> baseResponse = inonStandardValueService.nonValue(startParse, endParse, groups,name);
List<NonStandardValue> data = baseResponse.getData();
if (data.size() != 0) {
Page<NonStandardValue> rts = PageUtil.listConvertToPage(data, pageQuery);
return BaseResponse.okData(rts);
return inonStandardValueService.getPage(pageQuery, userId, name,startParse,endParse);
} catch (Exception e) {
log.debug("非标产值分页列表{}", e);
}
return baseResponse;
return BaseResponse.errorMsg("失败!");
}
@ApiOperation(value = "获取所有已通过的非标产值")
......@@ -99,21 +99,6 @@ public class NonStandardValueController {
return BaseResponse.errorMsg("失败!");
}
// @ApiOperation(value = "根据用户id查询指定非标产值信息")
// @GetMapping("/{userId}")
// public BaseResponse getByUserId(@PathVariable Integer userId) {
// try {
// BaseResponse<List<NonStandardValueVo>> e = inonStandardValueService.getByUserId(userId);
// if (e == null) {
// return BaseResponse.errorMsg("信息错误!");
// }
// return BaseResponse.okData(e);
// } catch (Exception e) {
// log.debug("通过用户id查询非标产值信息{}", e);
// }
// return BaseResponse.errorMsg("失败!");
// }
@ApiOperation("非标产值信息导出列表")
@PostMapping("/exportList")
public void exportList(String filename, Integer userId, String name, HttpServletResponse response) {
......
......@@ -6,13 +6,10 @@ import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.wise.sc.cement.business.entity.NormProduction;
import cn.wise.sc.cement.business.entity.NormProductionStatistics;
import cn.wise.sc.cement.business.model.vo.*;
import cn.wise.sc.cement.business.model.BaseResponse;
import cn.wise.sc.cement.business.model.LoginUser;
import cn.wise.sc.cement.business.model.PageQuery;
import cn.wise.sc.cement.business.model.vo.NormProductionVo;
import cn.wise.sc.cement.business.model.vo.ProductionVo;
import cn.wise.sc.cement.business.model.vo.WorkloadStatisticsVo;
import cn.wise.sc.cement.business.service.INonStandardValueService;
import cn.wise.sc.cement.business.service.INormProductionService;
import cn.wise.sc.cement.business.service.IPrecipriceService;
......@@ -21,7 +18,11 @@ import cn.wise.sc.cement.business.util.PageUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
......@@ -32,11 +33,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
/**
......@@ -52,6 +49,8 @@ import java.util.stream.Collectors;
@RequestMapping("/business/norm/production")
public class NormProductionController {
private static final Logger log = LoggerFactory.getLogger("NormProductionController");
final
INormProductionService iNormProductionService;
final
......@@ -68,24 +67,32 @@ public class NormProductionController {
this.iSysUserService = iSysUserService;
}
//*************************************产值设置***********************************************
@PostMapping("/create")
@ApiOperation("新增标准产值配置")
public BaseResponse<NormProduction> addObj(@RequestBody NormProduction normProduction) {
return iNormProductionService.addObj(normProduction);
}
@GetMapping("/page")
@ApiOperation("分页查询")
public BaseResponse<IPage<NormProductionVo>> page(PageQuery pageQuery) {
return iNormProductionService.getPage(pageQuery);
}
@PutMapping("/edit")
@ApiOperation("编辑标产值配置")
@ApiOperation("编辑标产值配置")
public BaseResponse<Boolean> edit(@RequestBody NormProduction production) {
return iNormProductionService.edit(production);
}
@GetMapping("/page")
@ApiOperation("标准产值配置分页列表")
@ApiImplicitParams(value = {
@ApiImplicitParam(name = "type", value = "类型 0:处理项 1:检测组 2:检测项", paramType = "query", dataType = "Integer")
})
public BaseResponse<IPage<NormProductionVo>> page(PageQuery pageQuery, Integer type) {
return iNormProductionService.getPage(pageQuery, type);
}
@GetMapping("/{id}")
@ApiOperation("根据id获取标准产值配置")
public BaseResponse<NormProduction> getById(@PathVariable("id") Integer id) {
......@@ -111,130 +118,90 @@ public class NormProductionController {
return iNormProductionService.activeOrForbidden(id);
}
//**************************************产值统计***********************************************************
@ApiOperation("产值统计-标准产值-分页列表")
@ApiImplicitParams(value = {
@ApiImplicitParam(name = "startDate", value = "开始日期", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "endDate", value = "结束日期", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "userName", value = "姓名", paramType = "query", dataType = "String")
})
@GetMapping("/statistics")
@ApiOperation("标准产值统计-分页")
public BaseResponse<Page<NormProductionStatistics>> normProductionStatistics(String start, String end, String name, Integer groupId, PageQuery pageQuery) {
Long startTime = null;
Long endTime = null;
if (StrUtil.isNotBlank(start) && StrUtil.isNotBlank(end)) {
startTime = DateUtil.parseDate(start).getTime();
endTime = DateUtil.parseDate(end).offsetNew(DateField.DAY_OF_MONTH, 1).getTime();
}
public BaseResponse statistics(PageQuery pageQuery, String startDate, String endDate, String userName) {
//将list拆分成分页
BaseResponse<List<NormProductionStatistics>> baseResponse = iPrecipriceService
.normProductionStatistics(startTime, endTime, name, groupId);
if (baseResponse.getCode() == 200) {
List<NormProductionStatistics> data = baseResponse.getData();
if (data.size() != 0) {
Page<NormProductionStatistics> rts = PageUtil.listConvertToPage(data, pageQuery);
return BaseResponse.okData(rts);
}
try {
return iPrecipriceService.normProductionStatistics(pageQuery, startDate, endDate, userName);
} catch (Exception e) {
log.debug("产值统计-标准产值-分页列表{}", e);
}
return BaseResponse.okData(new Page<>());
return BaseResponse.errorMsg("失败!");
}
@ApiOperation("产值统计-标准产值-列表")
@ApiImplicitParams(value = {
@ApiImplicitParam(name = "startDate", value = "开始日期", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "endDate", value = "结束日期", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "userName", value = "姓名", paramType = "query", dataType = "String")
})
@GetMapping("/statisticsList")
@ApiOperation("标准产值统计-列表")
public BaseResponse<List<NormProductionStatistics>> normProductionStatisticsList(String start, String end, String name, Integer groupId) {
public BaseResponse statisticsList(String startDate, String endDate, String userName) {
Long startTime = null;
Long endTime = null;
if (StrUtil.isNotBlank(start) && StrUtil.isNotBlank(end)) {
startTime = DateUtil.parseDate(start).getTime();
endTime = DateUtil.parseDate(end).offsetNew(DateField.DAY_OF_MONTH, 1).getTime();
try {
return iPrecipriceService.statisticsList(startDate, endDate, userName);
} catch (Exception e) {
log.debug("产值统计-标准产值-分页列表{}", e);
}
//将list拆分成分页
BaseResponse<List<NormProductionStatistics>> baseResponse = iPrecipriceService
.normProductionStatistics(startTime, endTime, name, groupId);
return baseResponse;
return BaseResponse.errorMsg("失败!");
}
//todo 人员工作统计导出
@GetMapping("/statistics/detail")
@ApiOperation("标准产值详情")
public BaseResponse<Page<NormProduction.NormProductionDetail>> normProductionDetails(Integer userId, String start,
String end, PageQuery pageQuery) {
Assert.notNull(userId, "用户id是必填的!");
Long startTime = null;
Long endTime = null;
if (StrUtil.isNotBlank(start) && StrUtil.isNotBlank(end)) {
startTime = DateUtil.parseDate(start).getTime();
endTime = DateUtil.parseDate(end).offsetNew(DateField.DAY_OF_MONTH, 1).getTime();
@ApiOperation("产值统计-标准产值-个人详情")
public BaseResponse normProductionDetails(PageQuery pageQuery, String startDate, String endDate, Integer userId) {
try {
return iPrecipriceService.normProductionDetails(pageQuery, startDate, endDate, userId);
} catch (Exception e) {
log.debug("产值统计-标准产值-个人详情{}", e);
}
List<NormProduction.NormProductionDetail> data = iPrecipriceService.normProductionDetails(userId, startTime, endTime);
List<NormProduction.NormProductionDetail> collect = data
.stream()
.filter(arg -> arg.getUserId().intValue() == userId)
.collect(Collectors.toList());
if (collect.size() != 0) {
Page<NormProduction.NormProductionDetail> rts = PageUtil.listConvertToPage(collect, pageQuery);
return BaseResponse.okData(rts);
return BaseResponse.errorMsg("失败!");
}
return BaseResponse.okData(new Page<>());
@GetMapping("/statistics/specificDetail")
@ApiOperation("产值统计-标准产值-个人详情-检测项目详情")
public BaseResponse normProductionSpecificDetails(PageQuery pageQuery,
String startDate, String endDate, Integer userId, Integer type, Integer objId) {
try {
return iPrecipriceService.normProductionSpecificDetails(pageQuery,
startDate, endDate, userId, type, objId);
} catch (Exception e) {
log.debug("产值统计-标准产值-个人详情-检测项目详情{}", e);
}
return BaseResponse.errorMsg("失败!");
}
@GetMapping("/total/production")
@ApiOperation("总产值统计")
@ApiOperation("产值统计-总产值统计")
public BaseResponse<Page<ProductionVo>> production(PageQuery pageQuery, String name, String start, String end, Integer groupId) {
Long startTime = null;
Long endTime = null;
if (StrUtil.isNotBlank(start) && StrUtil.isNotBlank(end)) {
startTime = DateUtil.parseDate(start).getTime();
endTime = DateUtil.parseDate(end).offsetNew(DateField.DAY_OF_MONTH, 1).getTime();
}
List<ProductionVo> rts = iPrecipriceService.production(name, startTime, endTime, groupId);
if (!CollectionUtil.isEmpty(rts)) {
Set<Integer> ids = new HashSet<>();
for (ProductionVo productionVo : rts) {
Integer groupId1 = productionVo.getGroupId();
ids.add(groupId1);
}
List<ProductionVo> newRts = new ArrayList<>();
for (Integer groupId1 : ids) {
for (ProductionVo productionVo : rts) {
ProductionVo finalNormProduction = new ProductionVo();
if (productionVo.getGroupId().intValue() == groupId1) {
finalNormProduction.setUserId(productionVo.getUserId());
finalNormProduction.setUserName(productionVo.getUserName());
finalNormProduction.setAccount(productionVo.getAccount());
finalNormProduction.setPositionId(productionVo.getPositionId());
finalNormProduction.setPosition(productionVo.getPosition());
finalNormProduction.setTime(productionVo.getTime());
finalNormProduction.setGroupId(productionVo.getGroupId());
finalNormProduction.setGroupName(productionVo.getGroupName());
Double newFinalValue = productionVo.getProductionTotalValue() + finalNormProduction.getProductionTotalValue();
finalNormProduction.setProductionTotalValue(newFinalValue);
Double newNonProductionValue = productionVo.getNonProductionValue() + finalNormProduction.getNonProductionValue();
finalNormProduction.setProductionValue(newNonProductionValue);
Double newProductionValue = productionVo.getProductionValue() + finalNormProduction.getProductionValue();
finalNormProduction.setNonProductionValue(newProductionValue);
}
newRts.add(finalNormProduction);
}
}
rts = newRts;
rts.stream().forEach(arg -> {
arg.setId(Integer.valueOf(arg.getUserId()));
arg.setProductionTotalValue(arg.getProductionValue() + arg.getNonProductionValue());
});
return BaseResponse.okData(PageUtil.listConvertToPage(rts.stream().sorted(Comparator.comparing(ProductionVo::getId)).collect(Collectors.toList()), pageQuery));
}
return BaseResponse.okData(PageUtil.listConvertToPage(rts, pageQuery));
}
@PostMapping("/export/statistics")
//****************************导出*****************************************************
/* @PostMapping("/export/statistics")
@ApiOperation("导出标准产值列表")
public void exportNormProductionStatistics(String start, String end, String name, Integer groupId, HttpServletResponse response) {
Long startTime = null;
......@@ -244,9 +211,9 @@ public class NormProductionController {
endTime = DateUtil.parseDate(end).offsetNew(DateField.DAY_OF_MONTH, 1).getTime();
}
iNormProductionService.exportNormProductionStatistics(startTime, endTime, name, groupId, response);
}
}*/
@PostMapping("/export/statistics/detail")
/* @PostMapping("/export/statistics/detail")
@ApiOperation("导出个人标准产值详情列表")
public void exportNormProductionDetails(Integer userId, String start,
String end, HttpServletResponse response) {
......@@ -257,9 +224,9 @@ public class NormProductionController {
endTime = DateUtil.parseDate(end).offsetNew(DateField.DAY_OF_MONTH, 1).getTime();
}
iPrecipriceService.exportNormProductionDetail(userId, startTime, endTime, response);
}
}*/
@PostMapping("/export/total/production")
/* @PostMapping("/export/total/production")
@ApiOperation("导出总产值")
public void exportProduction(String name, String start, String end, Integer groupId, HttpServletResponse response) {
Long startTime = null;
......@@ -270,31 +237,7 @@ public class NormProductionController {
}
iNormProductionService.exportProduction(name, startTime, endTime, groupId, response);
}
@GetMapping("/workload/statistics")
@ApiOperation("工作量统计")
public BaseResponse<List<WorkloadStatisticsVo>> workloadStatistics(String start, String end, Integer userId) {
LoginUser loginUser = iSysUserService.getLoginUser();
if (BeanUtil.isEmpty(loginUser)) {
return BaseResponse.errorMsg("请登录!");
}
if (!loginUser.getRoleList().getName().equals("系统管理员")) {
userId = loginUser.getId();
}
Date startTime = null;
Date endTime = DateUtil.date();
if (StrUtil.isNotBlank(start) && StrUtil.isNotBlank(end)) {
startTime = DateUtil.parseDate(start);
endTime = DateUtil.parseDate(end).offsetNew(DateField.DAY_OF_MONTH, 1);
}
return BaseResponse.okData(iPrecipriceService.workloadStatistics(startTime, endTime, userId));
}
}*/
}
package cn.wise.sc.cement.business.controller;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.wise.sc.cement.business.entity.NormProduction;
import cn.wise.sc.cement.business.entity.NormProductionStatistics;
import cn.wise.sc.cement.business.model.BaseResponse;
import cn.wise.sc.cement.business.model.PageQuery;
import cn.wise.sc.cement.business.model.vo.NormProductionVo;
import cn.wise.sc.cement.business.model.vo.ProductionVo;
import cn.wise.sc.cement.business.model.vo.WorkloadStatisticsVo;
import cn.wise.sc.cement.business.service.INonStandardValueService;
import cn.wise.sc.cement.business.service.INormProductionService;
import cn.wise.sc.cement.business.service.IPrecipriceService;
import cn.wise.sc.cement.business.util.PageUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
* <p>
* 前端控制器
* </p>
*
* @author ztw
* @since 2020-11-02
*/
@RestController
@Api(hidden = true)
@RequestMapping("/business/preciprice")
public class PrecipriceController {
@Autowired
IPrecipriceService iNormProductionService;
@Autowired
INonStandardValueService inonStandardValueService;
@GetMapping("/ddd")
@ApiOperation("aaa")
public void add(){
iNormProductionService.createPreciprice(1,1,1,1,1,true);
}
@GetMapping("/statistics")
@ApiOperation("标准产值统计")
public BaseResponse<Page<NormProductionStatistics>> normProductionStatistics(String start, String end, String name, Integer groupId, PageQuery pageQuery) {
Long startTime = null;
Long endTime = null;
if (StrUtil.isNotBlank(start) && StrUtil.isNotBlank(end)) {
startTime = DateUtil.parseDate(start).getTime();
endTime = DateUtil.parseDate(end).getTime();
}
//将list拆分成分页
BaseResponse<List<NormProductionStatistics>> baseResponse = iNormProductionService
.normProductionStatistics(startTime, endTime, name, groupId);
if (baseResponse.getCode() == 200) {
List<NormProductionStatistics> data = baseResponse.getData();
if (data.size() != 0) {
Page<NormProductionStatistics> rts = PageUtil.listConvertToPage(data, pageQuery);
return BaseResponse.okData(rts);
}
}
return BaseResponse.okData(null);
}
@GetMapping("/statistics/detail")
@ApiOperation("标准产值详情")
public BaseResponse<Page<NormProduction.NormProductionDetail>> normProductionDetails(Integer userId, String start,
String end, PageQuery pageQuery) {
Long startTime = null;
Long endTime = null;
if (StrUtil.isNotBlank(start) && StrUtil.isNotBlank(end)) {
startTime = DateUtil.parseDate(start).getTime();
endTime = DateUtil.parseDate(end).getTime();
}
List<NormProduction.NormProductionDetail> data = iNormProductionService.normProductionDetails(userId, startTime, endTime);
List<NormProduction.NormProductionDetail> collect = data
.stream()
.filter(arg -> arg.getUserId().intValue() == userId)
.collect(Collectors.toList());
if (collect.size() != 0) {
Page<NormProduction.NormProductionDetail> rts = PageUtil.listConvertToPage(collect, pageQuery);
return BaseResponse.okData(rts);
}
return BaseResponse.okData(null);
}
@GetMapping("/total/production")
@ApiOperation("总产值统计")
public BaseResponse<Page<ProductionVo>> production(PageQuery pageQuery, String name, String start, String end, Integer groupId) {
Long startTime = null;
Long endTime = null;
if (StrUtil.isNotBlank(start) && StrUtil.isNotBlank(end)) {
startTime = DateUtil.parseDate(start).getTime();
endTime = DateUtil.parseDate(end).getTime();
}
List<ProductionVo> rts = iNormProductionService.production(name, startTime, endTime, groupId);
if (!CollectionUtil.isEmpty(rts)) {
Set<Integer> ids = new HashSet<>();
for (ProductionVo productionVo : rts) {
Integer groupId1 = productionVo.getGroupId();
ids.add(groupId1);
}
List<ProductionVo> newRts = new ArrayList<>();
for (Integer groupId1 : ids) {
ProductionVo finalNormProduction = new ProductionVo();
for (ProductionVo productionVo : rts) {
if (productionVo.getGroupId().intValue() == groupId1) {
finalNormProduction.setUserId(productionVo.getUserId());
finalNormProduction.setUserName(productionVo.getUserName());
finalNormProduction.setAccount(productionVo.getAccount());
finalNormProduction.setPositionId(productionVo.getPositionId());
finalNormProduction.setPosition(productionVo.getPosition());
finalNormProduction.setTime(productionVo.getTime());
finalNormProduction.setGroupId(productionVo.getGroupId());
finalNormProduction.setGroupName(productionVo.getGroupName());
Double newFinalValue = productionVo.getProductionTotalValue() + finalNormProduction.getProductionTotalValue();
finalNormProduction.setProductionTotalValue(newFinalValue);
Double newNonProductionValue = productionVo.getNonProductionValue() + finalNormProduction.getNonProductionValue();
finalNormProduction.setNonProductionValue(newNonProductionValue);
Double newProductionValue = productionVo.getProductionValue() + finalNormProduction.getProductionValue();
finalNormProduction.setProductionValue(newProductionValue);
}
}
newRts.add(finalNormProduction);
}
rts = newRts;
}
return BaseResponse.okData(PageUtil.listConvertToPage(rts, pageQuery));
}
@PostMapping("/export/statistics")
@ApiOperation("导出标准产值列表")
public void exportNormProductionStatistics(String start, String end, String name, Integer groupId, HttpServletResponse response) {
Long startTime = null;
Long endTime = null;
if (StrUtil.isNotBlank(start) && StrUtil.isNotBlank(end)) {
startTime = DateUtil.parseDate(start).getTime();
endTime = DateUtil.parseDate(end).getTime();
}
iNormProductionService.exportNormProductionStatistics(startTime, endTime, name, groupId, response);
}
@PostMapping("/export/statistics/detail")
@ApiOperation("导出个人标准产值详情列表")
public void exportNormProductionDetails(Integer userId, String start,
String end, HttpServletResponse response) {
Long startTime = null;
Long endTime = null;
if (StrUtil.isNotBlank(start) && StrUtil.isNotBlank(end)) {
startTime = DateUtil.parseDate(start).getTime();
endTime = DateUtil.parseDate(end).getTime();
}
iNormProductionService.exportNormProductionDetail(userId, startTime, endTime, response);
}
@PostMapping("/export/total/production")
@ApiOperation("导出总产值")
public void exportProduction(String name, String start, String end, Integer groupId, HttpServletResponse response) {
Long startTime = null;
Long endTime = null;
if (StrUtil.isNotBlank(start) && StrUtil.isNotBlank(end)) {
startTime = DateUtil.parseDate(start).getTime();
endTime = DateUtil.parseDate(end).getTime();
}
iNormProductionService.exportProduction(name, startTime, endTime, groupId, response);
}
@GetMapping("/workload/statistics")
@ApiOperation("工作量统计")
public BaseResponse<List<WorkloadStatisticsVo>> workloadStatistics(String start, String end, Integer userId) {
Date startTime = null;
Date endTime = DateUtil.date();
if (StrUtil.isNotBlank(start) && StrUtil.isNotBlank(end)) {
startTime = DateUtil.parseDate(start);
endTime = DateUtil.parseDate(end);
}
return BaseResponse.okData(iNormProductionService.workloadStatistics(startTime, endTime, userId));
}
}
......@@ -36,13 +36,13 @@ public class NormProduction implements Serializable {
/**
* 检查组id
*/
@ApiModelProperty("检查组id")
@ApiModelProperty("对象id")
private Integer assessId;
/**
* 类型 1:检测组 0:处理
* 类型 0:处理项 1:检测组 2:检测
*/
@ApiModelProperty("类型 1:检测组 0:处理项")
@ApiModelProperty("类型 0:处理项 1:检测组 2:检测项")
private Integer type;
/**
......@@ -99,31 +99,43 @@ public class NormProduction implements Serializable {
@ApiModelProperty("状态")
private Integer status;
/**
* 标准产值详情
* 标准产值-人员详情(对象的数量)
*/
@Data
public static class NormProductionUserDetail implements Serializable{
private static final long serialVersionUID = 42L;
private Integer type;
private String userName;
private Integer objId;
private String objName;
private Integer countNums;
private BigDecimal countPricel;
}
/**
* 标准产值-检测项目详情(对象的具体信息)
*/
@Data
public static class NormProductionDetail implements Serializable{
private static final long serialVersionUID = 42L;
private String userName;
private Integer distributionId;
private Integer userId;
private Integer entrustId;
private Integer assessId;
private LocalDateTime checkTime;
private Double analyseRate;
private Double separateRate;
private Double assessRate;
private Double reportedResultRate;
private String objName;
private String projectName;
private String sampleName;
private String projectCode;
private String entrustCode;
private Integer sampleId;
private BigDecimal workTimeCoefficient;
private Integer type;
private String groupTeamName;
private LocalDateTime checkTime;
private BigDecimal countPricel;
private String cementCode;
}
}
......@@ -45,12 +45,12 @@ public class Preciprice implements Serializable {
private Integer sampleId;
/**
* 检测/处理Id
* 处理/检测组/检测项Id
*/
private Integer targetId;
/**
* 检测:1 处理:0
* 处理:0 检测组:1 检测项:2
*/
private Integer type;
......@@ -112,11 +112,17 @@ public class Preciprice implements Serializable {
/**
* 项目id
*/
private String entrustName;
private String projectName;
/**
* 项目编号
*/
private String projectCode;
/**
* 委托单号
*/
private String entrustCode;
/**
......@@ -137,7 +143,7 @@ public class Preciprice implements Serializable {
private String userName;
/**
* 检测组
* 对象
*/
private String groupTeamName;
/**
......
package cn.wise.sc.cement.business.mapper;
import cn.wise.sc.cement.business.entity.Preciprice;
import cn.wise.sc.cement.business.model.vo.EntrustVo;
import cn.wise.sc.cement.business.model.vo.NormProductionStatisticsVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
/**
* <p>
* Mapper 接口
......@@ -15,4 +22,8 @@ import org.apache.ibatis.annotations.Param;
public interface PrecipriceMapper extends BaseMapper<Preciprice> {
void updateStatusByEntrustId(@Param("param") Integer entrustId);
IPage<NormProductionStatisticsVo> getStatisticsPage(@Param("page") Page page, @Param("params") Map<String, Object> params);
List<NormProductionStatisticsVo> getStatisticsList(@Param("params") Map<String, Object> params);
}
......@@ -34,6 +34,9 @@ public interface SampleDistributionMapper extends BaseMapper<SampleDistribution>
List<SampleTeamGroupUserVo> getDistributionTeamGroupList(@Param("sampleId") Integer sampleId,
@Param("userId") Integer userId);
List<SampleCheckGroupVo> getSampleCheckGroupList(@Param("sampleId") Integer sampleId);
List<EntrustSample> getEntrustSample();
......
......@@ -17,7 +17,5 @@ import java.util.List;
*/
public interface TeamGroupMapper extends BaseMapper<TeamGroup> {
@Select("select id, name from team_group")
List<SummaryVo> fetchList();
}
......@@ -43,6 +43,7 @@ public interface TeamMapper extends BaseMapper<Team> {
SummaryListVo getSummaryList2();
List<Integer> getIdForGroup(Integer groupId);
......
......@@ -3,8 +3,91 @@
<mapper namespace="cn.wise.sc.cement.business.mapper.PrecipriceMapper">
<update id="updateStatusByEntrustId">
UPDATE preciprice SET `status` =1 WHERE entrust_id = #{param}
</update>
<select id="getStatisticsPage" resultType="cn.wise.sc.cement.business.model.vo.NormProductionStatisticsVo">
select
su.id as userId,su.name as userName, su.username as account,
(
CASE su.sex
WHEN 0 THEN '女'
WHEN 1 THEN '男'
ELSE NULL
END
) as sex,
(select count(*) from preciprice pp where pp.user_id = su.id
<if test="params.startDate != null">
and pp.create_time &gt;= #{params.startDate}
</if>
<if test="params.endDate != null">
and pp.create_time &lt;= #{params.endDate}
</if>
) as count,
(select IF(ISNULL(sum(pp.preciprice)),0,sum(pp.preciprice)) from preciprice pp where pp.user_id = su.id
<if test="params.startDate != null">
and pp.create_time &gt;= #{params.startDate}
</if>
<if test="params.endDate != null">
and pp.create_time &lt;= #{params.endDate}
</if>
) as coefficient
from sys_user su
left join sys_group sg on sg.id = su.group_id
where su.is_delete = 1 and sg.name = '实验室组'
<if test="params.userName != null and params.userName != ''">
and su.name like concat('%', #{params.userName}, '%')
</if>
<if test="params.userId != null">
and su.id = #{params.userId}
</if>
<if test="params.groupId != null">
and su.group_id = #{params.groupId}
</if>
order by su.id asc
</select>
<select id="getStatisticsList" resultType="cn.wise.sc.cement.business.model.vo.NormProductionStatisticsVo">
select
su.id as userId,su.name as userName, su.username as account,
(
CASE su.sex
WHEN 0 THEN '女'
WHEN 1 THEN '男'
ELSE NULL
END
) as sex,
(select count(*) from preciprice pp where pp.user_id = su.id
<if test="params.startDate != null">
and pp.create_time &gt;= #{params.startDate}
</if>
<if test="params.endDate != null">
and pp.create_time &lt;= #{params.endDate}
</if>
) as count,
(select IF(ISNULL(sum(pp.preciprice)),0,sum(pp.preciprice)) from preciprice pp where pp.user_id = su.id
<if test="params.startDate != null">
and pp.create_time &gt;= #{params.startDate}
</if>
<if test="params.endDate != null">
and pp.create_time &lt;= #{params.endDate}
</if>
) as coefficient
from sys_user su
left join sys_group sg on sg.id = su.group_id
where su.is_delete = 1 and sg.name = '实验室组'
<if test="params.userName != null and params.userName != ''">
and su.name like concat('%', #{params.userName}, '%')
</if>
<if test="params.userId != null">
and su.id = #{params.userId}
</if>
<if test="params.groupId != null">
and su.group_id = #{params.groupId}
</if>
order by su.id asc
</select>
</mapper>
......@@ -104,21 +104,18 @@
</select>
<select id="getDistributionTeamGroupList" resultType="cn.wise.sc.cement.business.model.vo.SampleTeamGroupUserVo">
select su.id as userId,
t.team_group_id as teamGroupId
select
t.user_id as userId,
t.team_group_id as teamGroupId,
t.team_id as teamId
from sample_distribution t
left join sys_user su on su.id = t.user_id
left join team s on s.id = t.team_id
left join team_group tg on tg.id = t.team_group_id
where t.sample_id = #{sampleId}
<if test="userId != null">
and t.user_id = #{userId}
</if>
group by t.team_group_id
group by t.team_group_id,t.team_id
</select>
<select id="getSampleCheckGroupList" resultType="cn.wise.sc.cement.business.model.vo.SampleCheckGroupVo">
......
......@@ -137,4 +137,21 @@
</select>
<select id="getIdForGroup" resultType="java.lang.Integer">
select t.id as name from team t where t.group_id = #{groupId} order by t.sort_no asc;
</select>
</mapper>
package cn.wise.sc.cement.business.entity;
package cn.wise.sc.cement.business.model.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* @description: 标准产值统计对象
* @author: qh
* @create: 2020-09-23 18:18
* @author: ztw
* @create: 2021-03-24
**/
@Data
public class NormProductionStatistics implements Serializable {
public class NormProductionStatisticsVo implements Serializable {
private static final long serialVersionUID = 42L;
private String userName;
@ApiModelProperty("用户id")
private String userId;
@ApiModelProperty("姓名")
private String userName;
@ApiModelProperty("账户")
private String account;
@ApiModelProperty("性别")
private String sex;
private String position;
private String time;
@ApiModelProperty("检测项目数")
private Long count;
@ApiModelProperty("产值绩效")
private Double coefficient;
private Integer groupId;
private String groupName;
}
......@@ -22,13 +22,13 @@ public class NormProductionVo {
/**
* 检查组id
*/
@ApiModelProperty("检查组id")
@ApiModelProperty("对象id")
private Integer assessId;
/**
* 类型 1:检测组 0:处理
* 类型 0:处理项 1:检测组 2:检测
*/
@ApiModelProperty("类型 1:检测组 0:处理项")
@ApiModelProperty("类型 0:处理项 1:检测组 2:检测项")
private String type;
/**
......
......@@ -8,8 +8,8 @@ import java.io.Serializable;
/**
* @description:
* @author: qh
* @create: 2020-09-30 14:16
* @author: ztw
* @create: 2021-03-24
**/
@Data
@ApiModel("总产值统计")
......@@ -19,26 +19,26 @@ public class ProductionVo implements Serializable {
/**
* 主键
*/
private Integer id;
@ApiModelProperty("用户id")
private String userId;
@ApiModelProperty("用户名")
@ApiModelProperty("姓名")
private String userName;
@ApiModelProperty("账号")
@ApiModelProperty("账户")
private String account;
@ApiModelProperty("职位id")
private Integer positionId;
@ApiModelProperty("职位")
private String position;
@ApiModelProperty("统计时间")
private String time;
@ApiModelProperty("性别")
private String sex;
@ApiModelProperty("标准产值")
private Double productionValue = 0D;
@ApiModelProperty("非标准产值")
@ApiModelProperty("非标产值")
private Double nonProductionValue = 0D;
@ApiModelProperty("总产值")
@ApiModelProperty("产值合计")
private Double productionTotalValue = 0D;
@ApiModelProperty("部门id")
private Integer groupId;
@ApiModelProperty("部门名")
private String groupName;
}
......@@ -21,6 +21,9 @@ public class SampleTeamGroupUserVo {
@ApiModelProperty("检测组id")
private Integer teamGroupId;
@ApiModelProperty("检测项id")
private Integer teamId;
}
......@@ -3,7 +3,6 @@ package cn.wise.sc.cement.business.service;
import cn.wise.sc.cement.business.entity.NonStandardValue;
import cn.wise.sc.cement.business.model.BaseResponse;
import cn.wise.sc.cement.business.model.PageQuery;
import cn.wise.sc.cement.business.model.vo.NonStandardApplyVo;
import cn.wise.sc.cement.business.model.vo.NonStandardValueVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
......@@ -29,19 +28,9 @@ public interface INonStandardValueService extends IService<NonStandardValue> {
*/
BaseResponse<IPage<NonStandardValueVo>> getPage(PageQuery pageQuery, Integer userId, String name,Date startParse,Date endParse);
/* //计算每个用户提交的非标产值
BaseResponse<List<NonStandardValue>> nonValue(Integer userId);*/
//计算每个用户提交的非标产值
BaseResponse<List<NonStandardValue>> nonValue(Date start, Date end, Integer groups,String name);
// /**
// * 通过用户id查询非标产值信息
// *
// * @return List
// */
// BaseResponse<List<NonStandardValueVo>> getByUserId(Integer userId);
/**
* 获取所有非标产值信息
......
package cn.wise.sc.cement.business.service;
import cn.wise.sc.cement.business.entity.NormProduction;
import cn.wise.sc.cement.business.entity.NormProductionStatistics;
import cn.wise.sc.cement.business.model.vo.NormProductionStatisticsVo;
import cn.wise.sc.cement.business.model.BaseResponse;
import cn.wise.sc.cement.business.model.PageQuery;
import cn.wise.sc.cement.business.model.vo.NormProductionVo;
......@@ -24,102 +24,15 @@ import java.util.List;
*/
public interface INormProductionService extends IService<NormProduction> {
/**
* 创建新的标准产值配置
*
* @param normProduction 标准产值
* @return BaseResponse
*/
BaseResponse<NormProduction> addObj(NormProduction normProduction);
/**
* 分页查询
*
* @param pageQuery 分页条件
* @return 数据
*/
BaseResponse<IPage<NormProductionVo>> getPage(PageQuery pageQuery);
BaseResponse<NormProduction> addObj(NormProduction normProduction);
/**
* 编辑标准产值
*
* @param production 标准产值
* @return bool
*/
BaseResponse<Boolean> edit(NormProduction production);
/**
* 启用禁用标准产值
*
* @param id id
* @return bool
*/
BaseResponse<Integer> activeOrForbidden(Integer id);
/**
* 标准产值统计
*
* @param start 开始时间
* @param end 结束时间
* @param groupId 部门id
* @return BaseResponse
*/
BaseResponse<List<NormProductionStatistics>> normProductionStatistics(Long start, Long end, String name, Integer groupId);
BaseResponse<IPage<NormProductionVo>> getPage(PageQuery pageQuery, Integer type);
/**
* 标准产值统计 单人详情
*
* @param userId 用户id
* @param start 开始时间
* @param end 结束时间
* @return 详细信息
*/
List<NormProduction.NormProductionDetail> normProductionDetails(Integer userId,
Long start, Long end);
/**
* 总产值统计
*
* @param name 用户
* @param start 开始时间
* @param end 结束时间
* @return 详细信息
*/
List<ProductionVo> production(String name,Long start,Long end,Integer groupId);
/**
* 导出标准统计
* @param start 开始时间
* @param end 结束时间
* @param name 人员名字
* @param groupId 部门id
* @param response 响应体
*/
void exportNormProductionStatistics(Long start, Long end,String name,Integer groupId, HttpServletResponse response);
/**
* 导出个人标准产值详情列表
* @param userId 用户id
* @param startTime 开始时间
* @param endTime 结束时间
* @param response 响应体
*/
void exportNormProductionDetail(Integer userId, Long startTime, Long endTime, HttpServletResponse response);
BaseResponse<Integer> activeOrForbidden(Integer id);
/**
* 导出产值总统计列表
* @param name 名字检索
* @param startTime 开始时间
* @param endTime 结束时间
* @param response 响应体
*/
void exportProduction(String name, Long startTime, Long endTime,Integer groupId,HttpServletResponse response);
/**
* 统计工作量
* @param startTime 开始时间
* @param endTime 结束时间
* @return 统计对象
*/
List<WorkloadStatisticsVo> workloadStatistics(Date startTime, Date endTime,Integer userId);
}
package cn.wise.sc.cement.business.service;
import cn.wise.sc.cement.business.entity.NormProduction;
import cn.wise.sc.cement.business.entity.NormProductionStatistics;
import cn.wise.sc.cement.business.model.PageQuery;
import cn.wise.sc.cement.business.model.vo.NormProductionStatisticsVo;
import cn.wise.sc.cement.business.entity.Preciprice;
import cn.wise.sc.cement.business.model.BaseResponse;
import cn.wise.sc.cement.business.model.vo.ProductionVo;
import cn.wise.sc.cement.business.model.vo.WorkloadStatisticsVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;
......@@ -25,82 +26,16 @@ public interface IPrecipriceService extends IService<Preciprice> {
final Integer targetId, final Integer type,
final Integer sampleId, boolean isUrgent);
/**
* 标准产值统计
*
* @param start 开始时间
* @param end 结束时间
* @param groupId 部门id
* @return BaseResponse
*/
BaseResponse<List<NormProductionStatistics>> normProductionStatistics(Long start, Long end, String name, Integer groupId);
/**
* 标准产值统计 单人详情
*
* @param userId 用户id
* @param start 开始时间
* @param end 结束时间
* @return 详细信息
*/
List<NormProduction.NormProductionDetail> normProductionDetails(Integer userId,
Long start, Long end);
/**
* 总产值统计
*
* @param name 用户
* @param start 开始时间
* @param end 结束时间
* @return 详细信息
*/
List<ProductionVo> production(String name, Long start, Long end, Integer groupId);
/**
* 导出标准统计
*
* @param start 开始时间
* @param end 结束时间
* @param name 人员名字
* @param groupId 部门id
* @param response 响应体
*/
void exportNormProductionStatistics(Long start, Long end, String name, Integer groupId, HttpServletResponse response);
BaseResponse<IPage<NormProductionStatisticsVo>> normProductionStatistics(PageQuery pageQuery, String startDate, String endDate, String userName);
BaseResponse<List<NormProductionStatisticsVo>> statisticsList(String startDate, String endDate,String userName);
/**
* 导出个人标准产值详情列表
*
* @param userId 用户id
* @param startTime 开始时间
* @param endTime 结束时间
* @param response 响应体
*/
void exportNormProductionDetail(Integer userId, Long startTime, Long endTime, HttpServletResponse response);
BaseResponse<IPage<NormProduction.NormProductionUserDetail>>normProductionDetails(PageQuery pageQuery, String startDate, String endDate, Integer userId);
/**
* 导出产值总统计列表
*
* @param name 名字检索
* @param startTime 开始时间
* @param endTime 结束时间
* @param response 响应体
*/
void exportProduction(String name, Long startTime, Long endTime, Integer groupId, HttpServletResponse response);
BaseResponse<IPage<NormProduction.NormProductionDetail>>normProductionSpecificDetails(PageQuery pageQuery,
String startDate, String endDate, Integer userId, Integer type, Integer objId);
/**
* 统计工作量
*
* @param startTime 开始时间
* @param endTime 结束时间
* @return 统计对象
*/
List<WorkloadStatisticsVo> workloadStatistics(Date startTime, Date endTime, Integer userId);
List<ProductionVo> production(String name, Long start, Long end, Integer groupId);
/**
* 根据报告id更新
*
* @param entrustId
* @return
*/
boolean updateStatusByEntrustId(Integer entrustId);
}
......@@ -141,6 +141,8 @@ public class EntrustServiceImpl extends ServiceImpl<EntrustMapper, Entrust> impl
private ITeamService teamService;
@Resource
private ISampleDistributionService sampleDistributionService;
@Resource
private NormProductionMapper normProductionMapper;
/**
* 委托分页
......@@ -1451,7 +1453,6 @@ public class EntrustServiceImpl extends ServiceImpl<EntrustMapper, Entrust> impl
sampleHandleEnclosureMapper.insert(sampleHandleEnclosure);*/
//获取产值信息
QueryWrapper<NormProduction> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("assess_id", handle.getId());
queryWrapper.eq("type", 0);
queryWrapper.eq("status", 1);
List<NormProduction> normProduction = iNormProductionService.list(queryWrapper);
......@@ -1460,7 +1461,7 @@ public class EntrustServiceImpl extends ServiceImpl<EntrustMapper, Entrust> impl
sampleMapper.deleteBatchIds(sampleList);
//还原本所编号最大值
redisUtil.setString("maxCementCode", redisMaxCementCode);
return BaseResponse.errorMsg("请配置处理项名称为" + handle.getName() + "的产值信息!");
return BaseResponse.errorMsg("请配置处理项的产值信息!");
}
}
//消息推送
......@@ -1601,7 +1602,6 @@ public class EntrustServiceImpl extends ServiceImpl<EntrustMapper, Entrust> impl
}
//获取产值信息
QueryWrapper<NormProduction> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("assess_id", handle.getId());
queryWrapper.eq("type", 0);
queryWrapper.eq("status", 1);
List<NormProduction> normProduction = iNormProductionService.list(queryWrapper);
......@@ -1610,7 +1610,7 @@ public class EntrustServiceImpl extends ServiceImpl<EntrustMapper, Entrust> impl
sampleMapper.deleteBatchIds(sampleList);
//还原本所编号最大值
// redisUtil.setString("maxCementCode", redisMaxCementCode);
return BaseResponse.errorMsg("请配置处理项名称为" + handle.getName() + "的产值信息!");
return BaseResponse.errorMsg("请配置处理项的产值信息!");
}
}
//消息推送
......@@ -2078,12 +2078,22 @@ public class EntrustServiceImpl extends ServiceImpl<EntrustMapper, Entrust> impl
//计算产值
if (sampleHandle.getHandleId() != null) {
try {
iPrecipriceService.createPreciprice(sampleHandle.getUserId(), entrust.getId(), sampleHandle.getHandleId(), 0, sample.getId(), false);
//判断该样品是否已经计算产值,如果参与过计算不进行再次的产值计算
QueryWrapper<Preciprice> ppWrapper = new QueryWrapper<>();
ppWrapper.eq("type", 0);
ppWrapper.eq("entrust_id", entrust.getId());
ppWrapper.eq("sample_id", sample.getId());
ppWrapper.eq("user_id", sampleHandle.getUserId());
List<Preciprice> ppList = iPrecipriceService.list(ppWrapper);
if(ppList == null || ppList.size()==0){
iPrecipriceService.createPreciprice(sampleHandle.getUserId(), entrust.getId(), null, 0, sample.getId(), false);
}
} catch (Exception e) {
System.out.println(e.getMessage());
return BaseResponse.errorMsg(e.getMessage());
}
}
QueryWrapper<SampleHandle> sampleHandleWrapper = new QueryWrapper<>();
sampleHandleWrapper.eq("sample_id", sample.getId());
sampleHandleWrapper.ne("status", 2);
......@@ -2485,10 +2495,21 @@ public class EntrustServiceImpl extends ServiceImpl<EntrustMapper, Entrust> impl
queryWrapper.eq("type", 1);
queryWrapper.eq("status", 1);
List<NormProduction> normProduction = iNormProductionService.list(queryWrapper);
if (normProduction == null || normProduction.size() != 1) {
if (normProduction == null || normProduction.size() == 0 ) {
//获取产值信息
QueryWrapper<NormProduction> queryWrapper2 = new QueryWrapper<>();
queryWrapper2.eq("assess_id", distributionTeamQuery.getTeamId());
queryWrapper2.eq("type", 2);
queryWrapper2.eq("status", 1);
List<NormProduction> normProduction2 = iNormProductionService.list(queryWrapper2);
TeamGroup teamGroup = teamGroupMapper.selectById(distributionTeamQuery.getTeamGroupId());
return BaseResponse.errorMsg("联系管理员.配置检测组名称为" + teamGroup.getName() + "产值信息!");
Team team = teamMapper.selectById(distributionTeamQuery.getTeamId());
if (normProduction2 == null || normProduction2.size() == 0 ) {
return BaseResponse.errorMsg("联系管理员.配置检测组名称为" + teamGroup.getName() + "或者检测项名称为"+ team.getName() +"产值信息!");
}
}
//消息推送
BaseResponse wrapper = userMessageService.sendMessage(distributionTeamQuery.getUserId(), "您有一条样品检测信息等待检测", entrust.getId(), SysUserMessage.MessageType.ENTRUST);
if (wrapper.getCode() != 200) {
......@@ -2895,12 +2916,53 @@ public class EntrustServiceImpl extends ServiceImpl<EntrustMapper, Entrust> impl
//计算产值
List<SampleTeamGroupUserVo> sampleDistributionTeamGroupVoList = distributionMapper.getDistributionTeamGroupList(sample.getId(), loginUser.getId());
if (sampleDistributionTeamGroupVoList != null && sampleDistributionTeamGroupVoList.size() > 0) {
List<Integer> teamGroupIdList = new ArrayList<>();
for (SampleTeamGroupUserVo sdVo : sampleDistributionTeamGroupVoList) {
try {
if (sdVo.getTeamGroupId() == null) {
return BaseResponse.errorMsg("当前登录人没有该样品的检测权限");
}
//先判断该检测是按照检测组计算产值 还是按照检测项计算产值
//如果时按照检测项,直接计算,如果是按照检测组,则需要判断检测组是否计算过,去除重复的检测组计算。
//然后判断是否已经参与过产值计算,如果参与过,不用再进行计算
//判断检测组是否配置
QueryWrapper<NormProduction> qw = new QueryWrapper<>();
qw.eq("type", 1);
qw.eq("assess_id", sdVo.getTeamGroupId());
List<NormProduction> npList = normProductionMapper.selectList(qw);
if (npList != null && npList.size() > 0) {
//判断该样品是否已经计算产值,如果参与过计算不进行再次的产值计算
QueryWrapper<Preciprice> ppWrapper = new QueryWrapper<>();
ppWrapper.eq("type", 1);
ppWrapper.eq("entrust_id", entrust.getId());
ppWrapper.eq("sample_id", sample.getId());
ppWrapper.eq("target_id", sdVo.getTeamGroupId());
ppWrapper.eq("user_id", sdVo.getUserId());
List<Preciprice> ppList = iPrecipriceService.list(ppWrapper);
if(ppList == null || ppList.size()==0){
iPrecipriceService.createPreciprice(sdVo.getUserId(), entrust.getId(), sdVo.getTeamGroupId(), 1, sample.getId(), false);
}
}else{
QueryWrapper<NormProduction> qw2 = new QueryWrapper<>();
qw2.eq("type", 2);
qw2.eq("assess_id", sdVo.getTeamId());
List<NormProduction> npList2 = normProductionMapper.selectList(qw2);
if (npList2 != null && npList2.size() > 0) {
//判断该样品是否已经计算产值,如果参与过计算不进行再次的产值计算
QueryWrapper<Preciprice> ppWrapper = new QueryWrapper<>();
ppWrapper.eq("type", 2);
ppWrapper.eq("entrust_id", entrust.getId());
ppWrapper.eq("sample_id", sample.getId());
ppWrapper.eq("target_id", sdVo.getTeamId());
ppWrapper.eq("user_id", sdVo.getUserId());
List<Preciprice> ppList = iPrecipriceService.list(ppWrapper);
if(ppList == null || ppList.size()==0){
iPrecipriceService.createPreciprice(sdVo.getUserId(), entrust.getId(), sdVo.getTeamId(), 2, sample.getId(), false);
}
}
}
} catch (Exception e) {
return BaseResponse.errorMsg(e.getMessage());
}
......
......@@ -7,11 +7,11 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.wise.sc.cement.business.entity.*;
import cn.wise.sc.cement.business.mapper.NormProductionMapper;
import cn.wise.sc.cement.business.mapper.TeamGroupMapper;
import cn.wise.sc.cement.business.mapper.TeamMapper;
import cn.wise.sc.cement.business.model.BaseResponse;
import cn.wise.sc.cement.business.model.PageQuery;
import cn.wise.sc.cement.business.model.vo.NormProductionVo;
import cn.wise.sc.cement.business.model.vo.ProductionVo;
import cn.wise.sc.cement.business.model.vo.WorkloadStatisticsVo;
import cn.wise.sc.cement.business.model.vo.*;
import cn.wise.sc.cement.business.service.*;
import cn.wise.sc.cement.business.util.ExcelUtil;
import cn.wise.sc.cement.business.util.RedisUtil;
......@@ -21,7 +21,9 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.math.RoundingMode;
......@@ -54,11 +56,6 @@ public class NormProductionServiceImpl extends ServiceImpl<NormProductionMapper,
* 标准产值配置信息 缓存
*/
final public Map<String, NormProduction> normProductionCache = new HashMap<>();
/**
*
*/
final String CALCULATE_HANDLE = "CALCULATE_HANDLE";
final String CALCULATE_DISTRIBUTION = "CALCULATE_DISTRIBUTION";
final
ISampleDistributionService iSampleDistributionService;
......@@ -73,6 +70,8 @@ public class NormProductionServiceImpl extends ServiceImpl<NormProductionMapper,
final
ITeamGroupService iTeamGroupService;
final
ITeamService iTeamService;
final
IHandleService iHandleService;
final
ISysPostService iSysPostService;
......@@ -82,6 +81,11 @@ public class NormProductionServiceImpl extends ServiceImpl<NormProductionMapper,
INonStandardApplyService iNonStandardApplyService;
final
RedisUtil redisUtil;
@Resource
private TeamMapper teamMapper;
@Resource
private TeamGroupMapper teamGroupMapper;
public NormProductionServiceImpl(ISampleDistributionService iSampleDistributionService,
ISampleHandleService iSampleHandleService,
......@@ -91,7 +95,9 @@ public class NormProductionServiceImpl extends ServiceImpl<NormProductionMapper,
ITeamGroupService iTeamGroupService, IHandleService iHandleService,
ISysPostService iSysPostService,
INonStandardValueService iNonStandardValueService,
INonStandardApplyService iNonStandardApplyService, RedisUtil redisUtil) {
INonStandardApplyService iNonStandardApplyService, RedisUtil redisUtil,
ITeamService iTeamService
) {
this.iSampleDistributionService = iSampleDistributionService;
this.iSampleHandleService = iSampleHandleService;
this.iSysUserService = iSysUserService;
......@@ -103,20 +109,80 @@ public class NormProductionServiceImpl extends ServiceImpl<NormProductionMapper,
this.iNonStandardValueService = iNonStandardValueService;
this.iNonStandardApplyService = iNonStandardApplyService;
this.redisUtil = redisUtil;
this.iTeamService = iTeamService;
}
/**
* 新增产值配置
* @param normProduction 标准产值
* @return
*/
@Transactional
@Override
public BaseResponse<NormProduction> addObj(NormProduction normProduction) {
if(normProduction.getType() == null){
return BaseResponse.errorMsg("类型不允许为空!");
}
if(normProduction.getAssessId() == null){
return BaseResponse.errorMsg("对象id不允许为空!");
}
//如果是处理项 只能添加一次
if(normProduction.getType() == 0){
//判断配置项目是否已存在
QueryWrapper<NormProduction> qw = new QueryWrapper<>();
qw.eq("assess_id", normProduction.getAssessId());
qw.eq("type", normProduction.getType());
qw.eq("status", 1);
int count = this.count(qw);
if (count != 0) {
if (count > 0) {
return BaseResponse.errorMsg("当前处理项标准产值已存在!");
}
}else{
//判断配置项目是否已存在
QueryWrapper<NormProduction> qw = new QueryWrapper<>();
qw.eq("type", normProduction.getType());
qw.eq("assess_id", normProduction.getAssessId());
int count = this.count(qw);
if (count > 0) {
return BaseResponse.errorMsg("当前标准产值已存在!");
}
}
//如果是检测组,判断检测组下面的检测项是否添加,如果添加进行提示。
if(normProduction.getType() == 1){
TeamGroup teamGroup = teamGroupMapper.selectById(normProduction.getAssessId());
if(teamGroup == null){
return BaseResponse.errorMsg("检测组信息有误!");
}
List<Integer> idList = teamMapper.getIdForGroup(normProduction.getAssessId());
if(idList!= null && idList.size()>0){
for(Integer teamId : idList){
QueryWrapper<NormProduction> qw1 = new QueryWrapper<>();
qw1.eq("type", 2);
qw1.eq("assess_id", teamId);
int count1 = this.count(qw1);
if (count1 > 0) {
return BaseResponse.errorMsg("检测组中检测项的配置已存在!");
}
}
}
}
//如果是检测项 判断对应的检测组是否已经添加,如果添加进行提示。
if(normProduction.getType() == 2){
Team team = teamMapper.selectById(normProduction.getAssessId());
if(team == null){
return BaseResponse.errorMsg("检测项信息有误!");
}
if(team!= null && team.getGroupId() != null){
QueryWrapper<NormProduction> qw1 = new QueryWrapper<>();
qw1.eq("type", 1);
qw1.eq("assess_id", team.getGroupId());
int count1 = this.count(qw1);
if (count1 > 0) {
return BaseResponse.errorMsg("检测项所在检测组的配置已存在!");
}
}
}
//判断比例是否为总值100%
if (normProduction.getAnalyseRate()
+ normProduction.getAssessRate()
......@@ -135,60 +201,171 @@ public class NormProductionServiceImpl extends ServiceImpl<NormProductionMapper,
}
}
/**
* 修改产值配置
* @param normProduction
* @return
*/
@Transactional
@Override
public BaseResponse<IPage<NormProductionVo>> getPage(PageQuery pageQuery) {
public BaseResponse<Boolean> edit(NormProduction normProduction) {
if (normProduction.getId() == null ) {
return BaseResponse.errorMsg("参数错误!");
}
if(normProduction.getType() == null){
return BaseResponse.errorMsg("类型不允许为空!");
}
if(normProduction.getAssessId() == null){
return BaseResponse.errorMsg("对象id不允许为空!");
}
NormProduction normProductionOld = this.getById(normProduction.getId());
if(normProductionOld == null){
return BaseResponse.errorMsg("信息错误!");
}
//如果是处理项 只能添加一次
if(normProduction.getType() == 0){
//判断配置项目是否已存在
QueryWrapper<NormProduction> qw = new QueryWrapper<>();
qw.eq("type", normProduction.getType());
qw.ne("id", normProductionOld.getId());
int count = this.count(qw);
if (count > 0) {
return BaseResponse.errorMsg("当前处理项标准产值已存在!");
}
}else{
//判断配置项目是否已存在
QueryWrapper<NormProduction> qw = new QueryWrapper<>();
qw.eq("assess_id", normProduction.getAssessId());
qw.eq("type", normProduction.getType());
qw.ne("id", normProductionOld.getId());
int count = this.count(qw);
if (count > 0) {
return BaseResponse.errorMsg("当前标准产值已存在!");
}
}
//如果是检测组,判断检测组下面的检测项是否添加,如果添加进行提示。
if(normProduction.getType() == 1){
TeamGroup teamGroup = teamGroupMapper.selectById(normProduction.getAssessId());
if(teamGroup == null){
return BaseResponse.errorMsg("检测组信息有误!");
}
List<Integer> idList = teamMapper.getIdForGroup(normProduction.getAssessId());
if(idList!= null && idList.size()>0){
for(Integer teamId : idList){
QueryWrapper<NormProduction> qw1 = new QueryWrapper<>();
qw1.eq("type", 2);
qw1.eq("assess_id", teamId);
int count1 = this.count(qw1);
if (count1 > 0) {
return BaseResponse.errorMsg("检测组中检测项的配置已存在!");
}
}
}
}
//如果是检测项 判断对应的检测组是否已经添加,如果添加进行提示。
if(normProduction.getType() == 2){
Team team = teamMapper.selectById(normProduction.getAssessId());
if(team == null){
return BaseResponse.errorMsg("检测项信息有误!");
}
if(team!= null && team.getGroupId() != null){
QueryWrapper<NormProduction> qw1 = new QueryWrapper<>();
qw1.eq("type", 1);
qw1.eq("assess_id", team.getGroupId());
int count1 = this.count(qw1);
if (count1 > 0) {
return BaseResponse.errorMsg("检测项所在检测组的配置已存在!");
}
}
}
//判断比例是否为总值100%
if (normProduction.getAnalyseRate()
+ normProduction.getAssessRate()
+ normProduction.getSeparateRate()
+ normProduction.getReportedResultRate() != 1) {
return BaseResponse.errorMsg("百分比总和不等于1");
}
boolean b = this.updateById(normProduction);
if (b) {
return BaseResponse.okData(true);
} else {
return BaseResponse.errorMsg("修改失败!");
}
}
/**
* 产值配置分页列表
* @param pageQuery 分页条件
* @return
*/
@Override
public BaseResponse<IPage<NormProductionVo>> getPage(PageQuery pageQuery,Integer type) {
IPage<NormProduction> page = new Page<>(pageQuery.getPageNo(), pageQuery.getPageSize());
IPage<NormProduction> productionIPage = this.page(page);
QueryWrapper<NormProduction> qw = new QueryWrapper<>();
if(type != null){
qw.eq("type", type);
}
IPage<NormProduction> productionIPage = this.page(page, qw);
//关联名字
List<NormProduction> normProductions = productionIPage.getRecords();
List<Integer> npTeamGroupIds = new ArrayList<>(normProductions.size());
List<Integer> npHandleIds = new ArrayList<>(normProductions.size());
List<Integer> npTeamIds = new ArrayList<>(normProductions.size());
normProductions.forEach(arg -> {
if (arg.getType() == 1) {
if(arg.getType() == 1) {
npTeamGroupIds.add(arg.getAssessId());
} else {
npHandleIds.add(arg.getAssessId());
}else if(arg.getType() == 2) {
npTeamIds.add(arg.getAssessId());
}
});
if (npTeamGroupIds.size() == 0 && npHandleIds.size() == 0) {
return BaseResponse.errorMsg("没找着相关数据!关联检测组失败!");
}
List<Handle> handles = new ArrayList<>();
if (npHandleIds.size() != 0) {
handles = iHandleService.listByIds(npHandleIds);
}
List<TeamGroup> teamGroups = new ArrayList<>();
if (npTeamGroupIds.size() != 0) {
teamGroups = iTeamGroupService.listByIds(npTeamGroupIds);
}
List<Team> teams = new ArrayList<>();
if (npTeamIds.size() != 0) {
teams = iTeamService.listByIds(npTeamIds);
}
IPage<NormProductionVo> rts = new Page<>(pageQuery.getPageNo(), pageQuery.getPageSize());
List<NormProductionVo> records = new ArrayList<>(pageQuery.getPageSize());
rts.setTotal(productionIPage.getTotal());
rts.setCurrent(productionIPage.getCurrent());
rts.setPages(productionIPage.getPages());
rts.setSize(productionIPage.getSize());
List<TeamGroup> finalTeamGroups = teamGroups;
List<Handle> finalHandles = handles;
List<Team> finalTeams = teams;
normProductions.forEach(arg -> {
NormProductionVo normProductionVo = new NormProductionVo();
BeanUtil.copyProperties(arg, normProductionVo);
normProductionVo.setAssessName("/");
if (arg.getType() == 1) {
if (arg.getType() == 0) {
normProductionVo.setAssessName("处理项");
} else if(arg.getType() == 1) {
finalTeamGroups.stream()
.filter(opt -> opt.getId().intValue() == arg.getAssessId())
.findFirst()
.ifPresent(opt -> normProductionVo.setAssessName(opt.getName()));
} else {
finalHandles.stream()
} else if(arg.getType() == 2) {
finalTeams.stream()
.filter(opt -> opt.getId().intValue() == arg.getAssessId())
.findFirst()
.ifPresent(opt -> normProductionVo.setAssessName(opt.getName()));
}
if (arg.getType() == 1) {
normProductionVo.setType("检测项");
} else {
if (arg.getType() == 0) {
normProductionVo.setType("处理项");
}else if(arg.getType() == 1) {
normProductionVo.setType("检测组");
}else if(arg.getType() == 2) {
normProductionVo.setType("检测项");
}
records.add(normProductionVo);
});
......@@ -196,40 +373,11 @@ public class NormProductionServiceImpl extends ServiceImpl<NormProductionMapper,
return BaseResponse.okData(rts);
}
@Override
public BaseResponse<Boolean> edit(NormProduction production) {
if (production.getId() == null || production.getId() <= 0) {
return BaseResponse.errorMsg("编号id是必须的!");
}
//判断比例是否为总值100%
if (production.getAnalyseRate()
+ production.getAssessRate()
+ production.getSeparateRate()
+ production.getReportedResultRate() != 1) {
return BaseResponse.errorMsg("百分比总和不等于1");
}
//判断配置项目是否已存在
QueryWrapper<NormProduction> qw = new QueryWrapper<>();
qw.eq("assess_id", production.getAssessId());
qw.eq("type", production.getType());
qw.eq("status", 1);
NormProduction one = this.getOne(qw);
if (one != null && one.getId().intValue() != production.getId()) {
return BaseResponse.errorMsg("当前标准产值已存在!");
}
boolean b = this.updateById(production);
if (b) {
return BaseResponse.okData(true);
} else {
return BaseResponse.errorMsg("修改失败!");
}
}
/**
* 启用禁用标准产值
* @param id id
* @return
*/
@Override
public BaseResponse<Integer> activeOrForbidden(Integer id) {
......@@ -247,767 +395,6 @@ public class NormProductionServiceImpl extends ServiceImpl<NormProductionMapper,
}
@Override
public BaseResponse<List<NormProductionStatistics>> normProductionStatistics(Long start, Long end, String name, Integer groupId) {
//统计分样处理的详情
List<NormProduction.NormProductionDetail> normProductionDetails =
normProductionDetails(null, start, end);
if (normProductionDetails.size() == 0) {
BaseResponse<List<NormProductionStatistics>> rts = BaseResponse.okData(null);
rts.setData(new ArrayList<>());
return rts;
}
Map<Integer, BigDecimal> coefficientMap = new HashMap<>(normProductionDetails.size());
normProductionDetails
.forEach(arg -> {
Integer userId = arg.getUserId();
//不存在 添加
if (!coefficientMap.containsKey(userId)) {
coefficientMap.put(userId, arg.getWorkTimeCoefficient());
} else {
BigDecimal bigDecimal = coefficientMap.get(userId);
BigDecimal newWorkTime = arg.getWorkTimeCoefficient().add(bigDecimal);
coefficientMap.put(userId, newWorkTime);
}
});
List<NormProductionStatistics> rts = new ArrayList<>();
Set<Integer> userIds = coefficientMap.keySet();
QueryWrapper<SysUser> qw = new QueryWrapper<>();
qw.in("id", userIds);
List<SysUser> users = iSysUserService.list(qw);
List<SysPost> sysPosts = iSysPostService.list();
List<SysGroup> sysGroups = iSysGroupService.list();
for (Integer userId : coefficientMap.keySet()) {
SysUser sysUser = users.stream()
.filter(arg -> arg.getId().intValue() == userId)
.findFirst().orElse(null);
SysGroup sysGroup = sysGroups.stream().filter(arg -> arg.getId().intValue() == userId)
.findFirst().orElse(null);
if (sysUser == null) {
continue;
}
if (sysGroup == null) {
log.debug("用户分组未设置!关联用户部门失败!");
continue;
}
NormProductionStatistics productionStatistics = new NormProductionStatistics();
productionStatistics.setAccount(sysUser.getUsername());
productionStatistics.setCoefficient(coefficientMap.get(userId).doubleValue());
productionStatistics.setTime("/");
productionStatistics.setCount(normProductionDetails.stream()
.filter(arg -> arg.getUserId().intValue() == sysUser.getId())
.count());
productionStatistics.setPosition(sysUser.getQualifications());
if (start != null && end != null) {
DateTime startTime = DateUtil.date(start);
DateTime endTime = DateUtil.date(end);
productionStatistics.setTime(startTime.toDateStr() + "-" + endTime.toDateStr());
}
productionStatistics.setSex(sysUser.getSex() == 0 ? "女" : "男");
productionStatistics.setUserId(sysUser.getId() + "");
productionStatistics.setUserName(sysUser.getName());
productionStatistics.setGroupId(sysUser.getGroupId());
productionStatistics.setGroupName(sysGroup.getName());
SysPost sysPost = sysPosts.stream()
.filter(arg -> arg.getId().intValue() == sysUser.getPostId()).
findFirst().orElse(null);
productionStatistics.setPosition(sysPost == null ? "职务一" : sysPost.getName());
productionStatistics.setGroupName(sysGroup.getName());
rts.add(productionStatistics);
}
//过滤名字
if (StrUtil.isNotBlank(name)) {
List<NormProductionStatistics> collect = rts.stream().filter(arg -> arg.getUserName().contains(name)).collect(Collectors.toList());
return BaseResponse.okData(collect);
}
//过滤部门id
if (groupId != null) {
List<NormProductionStatistics> collect = rts.stream().filter(arg -> arg.getGroupId().equals(groupId)).collect(Collectors.toList());
return BaseResponse.okData(collect);
}
return BaseResponse.okData(rts);
}
@Override
public List<NormProduction.NormProductionDetail> normProductionDetails(
Integer userId, Long start, Long end) {
/*
* 计算的地方: 分样派发和分样处理表
* userId == null,计算所有人数据。
* userId != null,计算单人时间线的数据。
* 当start==0&&end==0时计算历史所有数据
*
* 过程:
* 1.获取分样派发表数据,然后获取标准产值配置,它的检测组相同。
* 3.每条记录*标准产值计算出来的结果。==>得出详情信息。
* 处理项目:
* 1.获取处理派发表数据,获取标准产值配置,查询处理项。
* */
//获取标准产值数据
Map<String, Object> params = new HashMap<>(2);
if (userId != null && userId > 0) {
params.put("user_id", userId);
}
if (start != null && end != null) {
DateTime startTime = DateUtil.date(start);
DateTime endTime = DateUtil.date(end);
params.put("start_time", DateUtil.format(startTime, "yyyy-MM-dd"));
params.put("end_time", DateUtil.format(endTime, "yyyy-MM-dd"));
}
//计算分析任务单产值
List<NormProduction.NormProductionDetail> sampleDistributionDetail = calculateSampleDistributionOptimize(params);
//计算处理任务单产值
List<NormProduction.NormProductionDetail> sampleHandleDetail = calculateSampleHandleOptimize(params);
//todo 计算校核任务单产值
// List<NormProduction.NormProductionDetail> sampleCheckTeamDetail = calculateSampleCheck(qwCT);
//todo 计算报出结果产值
List<NormProduction.NormProductionDetail> rts = new ArrayList<>(
sampleDistributionDetail.size()
+ sampleHandleDetail.size());
rts.addAll(sampleDistributionDetail);
rts.addAll(sampleHandleDetail);
//关联用户名字
List<Integer> userIds = rts.stream()
.map(NormProduction.NormProductionDetail::getUserId)
.collect(Collectors.toList());
if (userIds.size() == 0) {
return new ArrayList<>();
}
List<SysUser> users = iSysUserService.listByIds(userIds);
rts.forEach(arg -> users.stream()
.filter(opt -> opt.getId().intValue() == arg.getUserId())
.findFirst()
.ifPresent(sysUser -> arg.setUserName(sysUser.getName())));
return rts;
}
@Override
public List<ProductionVo> production(String name, Long start, Long end, Integer groupId) {
Date startDate = null;
Date endDate = new Date();
if (start != null && start != 0) {
startDate = DateUtil.date(start);
}
if (end != null && end != 0) {
endDate = DateUtil.date(end);
}
//非标准产值
List<NonStandardValue> nonStandardValues = iNonStandardValueService.nonValue(startDate, endDate, groupId, name).getData();
//标准产值
List<NormProductionStatistics> productionStatistics = this.normProductionStatistics(start, end, name, groupId).getData();
//以userId找关系
Set<String> userIds = new HashSet<>();
nonStandardValues.forEach(arg -> userIds.add(arg.getUserId() + ""));
productionStatistics.forEach(arg -> userIds.add(arg.getUserId()));
List<ProductionVo> rts = new ArrayList<>(userIds.size());
userIds.forEach(arg -> {
ProductionVo productionVo = new ProductionVo();
productionVo.setUserId(arg);
//找到标准准产值里面的数据
productionStatistics.forEach(opt -> {
if (opt.getUserId().equals(arg)) {
productionVo.setProductionValue(opt.getCoefficient());
productionVo.setUserName(opt.getUserName());
productionVo.setPosition(opt.getPosition());
productionVo.setAccount(opt.getAccount());
productionVo.setGroupId(opt.getGroupId());
productionVo.setGroupName(opt.getGroupName());
}
});
//找到标准产值里面的数据
nonStandardValues.forEach(opt -> {
if (arg.equals(opt.getUserId() + "")) {
productionVo.setNonProductionValue(opt.getFinalValue());
}
});
rts.add(productionVo);
});
//处理非标准产值没有用名职位信息
QueryWrapper<SysUser> qw = new QueryWrapper<>();
qw.in("id", userIds);
if (CollectionUtil.isEmpty(userIds)) {
return null;
}
List<SysUser> users = iSysUserService.list(qw);
List<SysPost> sysPosts = iSysPostService.list();
List<SysGroup> sysGroups = iSysGroupService.list();
Date finalStartDate = startDate;
Date finalEndDate = endDate;
rts.forEach(arg -> {
arg.setTime(finalStartDate == null ? "/" : DateUtil.format(finalStartDate, "yyyy-MM-dd") + "--" + DateUtil.format(finalEndDate, "yyyy-MM-dd"));
if (StrUtil.isBlank(arg.getUserName())) {
//关联用户信息
users.stream().filter(opt -> arg.getUserId().equals(opt.getId() + "")).findFirst()
.ifPresent(opt -> {
arg.setUserName(opt.getName());
arg.setAccount(opt.getUsername());
arg.setPositionId(opt.getPostId());
arg.setGroupId(opt.getGroupId());
});
//关联职务
sysPosts.stream().filter(opt -> arg.getPositionId().intValue() == opt.getId())
.findFirst()
.ifPresent(opt -> arg.setPosition(opt.getName()));
sysGroups.stream().filter(opt -> arg.getGroupId().intValue() == opt.getId())
.findFirst()
.ifPresent(opt -> arg.setGroupName(opt.getName()));
}
arg.setProductionTotalValue(arg.getNonProductionValue() + arg.getProductionValue());
});
//过滤名字
if (StrUtil.isNotBlank(name)) {
return rts.stream().filter(arg -> arg.getUserName().contains(name))
.collect(Collectors.toList());
}
//过滤部门id
if (groupId != null) {
return rts.stream().filter(arg -> arg.getGroupId().equals(groupId))
.collect(Collectors.toList());
}
return rts;
}
@Override
public void exportNormProductionStatistics(Long start, Long end, String name, Integer groupId, HttpServletResponse response) {
BaseResponse<List<NormProductionStatistics>> listBaseResponse = normProductionStatistics(start, end, name, groupId);
if (listBaseResponse.getCode() == 200) {
List<NormProductionStatistics> data = listBaseResponse.getData();
if (CollectionUtil.isNotEmpty(data)) {
String[] headers = new String[10];
headers[0] = "用户编号";
headers[1] = "用户名";
headers[2] = "账号";
headers[3] = "性别";
headers[4] = "职务";
headers[5] = "统计时间";
headers[6] = "检测项目数";
headers[7] = "产值绩效";
headers[8] = "部门id";
headers[9] = "部门名";
List<Object[]> exportData = new ArrayList<>(data.size());
for (NormProductionStatistics productionStatistics : data) {
Object[] objs = new Object[10];
objs[0] = productionStatistics.getUserId();
objs[1] = productionStatistics.getUserName();
objs[2] = productionStatistics.getAccount();
objs[3] = productionStatistics.getSex();
objs[4] = productionStatistics.getPosition();
objs[5] = productionStatistics.getTime();
objs[6] = productionStatistics.getCount();
objs[7] = productionStatistics.getCoefficient();
objs[8] = productionStatistics.getGroupId();
objs[9] = productionStatistics.getGroupName();
exportData.add(objs);
}
ExcelUtil.excelExport(
"标准产值统计", headers,
exportData, response);
}
}
}
@Override
public void exportNormProductionDetail(Integer userId, Long startTime, Long endTime, HttpServletResponse response) {
List<NormProduction.NormProductionDetail> normProductionDetails = normProductionDetails(userId, startTime, endTime);
if (CollectionUtil.isNotEmpty(normProductionDetails)) {
String[] headers = new String[13];
headers[0] = "序号";
headers[1] = "名字";
headers[2] = "检测项目";
headers[3] = "所属项目";
headers[4] = "项目编号";
headers[5] = "检测时间";
headers[6] = "分析占比";
headers[7] = "分样占比";
headers[8] = "校核占比";
headers[9] = "报结果占比";
headers[10] = "合计";
List<Object[]> exportData = new ArrayList<>(normProductionDetails.size());
int count = 0;
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日 hh:mm:ss");
for (NormProduction.NormProductionDetail target : normProductionDetails) {
Object[] objs = new Object[13];
objs[0] = count++;
objs[1] = target.getUserName();
objs[2] = target.getGroupTeamName();
objs[3] = target.getProjectName();
objs[4] = target.getEntrustCode();
objs[5] = target.getCheckTime() == null ? "/" : target.getCheckTime().format(timeFormatter);
objs[6] = target.getAnalyseRate();
objs[7] = target.getSeparateRate();
objs[8] = target.getAssessRate();
objs[9] = target.getReportedResultRate();
objs[10] = target.getWorkTimeCoefficient();
exportData.add(objs);
}
ExcelUtil.excelExport("标准产值详情—" + normProductionDetails.get(0).getUserName(), headers, exportData, response);
}
}
@Override
public void exportProduction(String name, Long startTime, Long endTime, Integer groupId, HttpServletResponse response) {
List<ProductionVo> data = production(name, startTime, endTime, groupId);
if (CollectionUtil.isNotEmpty(data)) {
String[] headers = new String[10];
headers[0] = "序号";
headers[1] = "姓名";
headers[2] = "账户";
headers[3] = "职务";
headers[4] = "统计时间";
headers[5] = "标准产值";
headers[6] = "非标准产值";
headers[7] = "产值统计";
headers[8] = "部门id";
headers[9] = "部门名";
List<Object[]> exportData = new ArrayList<>(data.size());
int count = 0;
for (ProductionVo target : data) {
Object[] objs = new Object[10];
objs[0] = count++;
objs[1] = target.getUserName();
objs[2] = target.getAccount();
objs[3] = target.getPosition();
objs[4] = target.getTime();
objs[5] = target.getProductionValue();
objs[6] = target.getNonProductionValue();
objs[7] = target.getProductionTotalValue();
objs[8] = target.getGroupId();
objs[9] = target.getGroupName();
exportData.add(objs);
}
ExcelUtil.excelExport("产值统计", headers, exportData, response);
}
}
@Override
public List<WorkloadStatisticsVo> workloadStatistics(Date startTime, Date endTime, Integer userId) {
long start = getDefaultStart(startTime == null ? 0 : startTime.getTime());
long end = getDefaultEnd(endTime.getTime());
Map<String, Integer> map1 = initMonthMoneyMap(start, end);
Map<String, Integer> map2 = initMonthMoneyMap(start, end);
QueryWrapper<SampleDistribution> qw = new QueryWrapper<>();
if (startTime != null) {
qw.ge("finish_time", DateUtil.format(DateUtil.date(start), "yyyy-MM-dd"));
}
if (userId != null && userId != 0) {
qw.eq("user_id", userId);
}
qw.le("finish_time", DateUtil.format(DateUtil.date(end), "yyyy-MM-dd"));
qw.eq("status", 2);
List<SampleDistribution> sampleDistributions = iSampleDistributionService.list(qw);
QueryWrapper<NonStandardApply> qwA = new QueryWrapper<>();
if (startTime != null) {
qwA.ge("start_time", DateUtil.format(DateUtil.date(start), "yyyy-MM-dd"));
}
if (userId != null && userId != 0) {
qwA.eq("user_id", userId);
}
qwA.le("start_time", DateUtil.format(DateUtil.date(end), "yyyy-MM-dd"));
qwA.eq("status", 2);
List<NonStandardApply> nonStandardApplies = iNonStandardApplyService.list(qwA);
for (SampleDistribution sampleDistribution : sampleDistributions) {
addCount(sampleDistribution.getFinishTime(), map1);
}
for (NonStandardApply nonStandardApply : nonStandardApplies) {
addCount(nonStandardApply.getStartTime(), map2);
}
WorkloadStatisticsVo workloadStatisticsVo = new WorkloadStatisticsVo();
workloadStatisticsVo.setType(0);
workloadStatisticsVo.setMap(map1);
WorkloadStatisticsVo workloadStatisticsVo2 = new WorkloadStatisticsVo();
workloadStatisticsVo2.setType(1);
workloadStatisticsVo2.setMap(map2);
List<WorkloadStatisticsVo> rts = new ArrayList<>(2);
rts.add(workloadStatisticsVo);
rts.add(workloadStatisticsVo2);
return rts;
}
private void addCount(LocalDateTime date, Map<String, Integer> map) {
Date nextDate = DateUtil.endOfMonth(asDate(date));
map.put(nextDate.getMonth() + 1 + "", map.get(nextDate.getMonth() + 1 + "") + 1);
}
private void addCount(LocalDate date, Map<String, Integer> map) {
Date nextDate = DateUtil.endOfMonth(asDate(date));
map.put(nextDate.getMonth() + 1 + "", map.get(nextDate.getMonth() + 1 + "") + 1);
}
private static Date asDate(LocalDate localDate) {
return Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
}
private static Date asDate(LocalDateTime localDateTime) {
return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
}
private Map<String, Integer> initMonthMoneyMap(long start, long end) {
Map<String, Integer> map = new LinkedHashMap();
for (long i = start; i <= end; i = DateUtil.offsetMonth(DateUtil.date(i), 1).getTime()) {
map.put(DateUtil.endOfMonth(DateUtil.date(i)).getMonth() + 1 + "", 0);
}
return map;
}
private static long getDefaultStart(long start) {
//如果没传时间进来 默认开始时间是今天开始时间
if (start == 0) {
start = System.currentTimeMillis();
start = DateUtil.beginOfYear(DateUtil.date(start)).getTime();
}
return start;
}
private static long getDefaultEnd(long end) {
//如果没传时间进来 默认开始时间是今天开始时间
if (end == 0) {
end = System.currentTimeMillis();
end = DateUtil.endOfYear(DateUtil.date(end)).getTime();
}
return end;
}
/**
* 计算处理派发单每条数据的标准产值
* (已有替代方法)
*
* @param qwHan 统计条件
* @return 处理任务详情
* @Deprecated 已废弃
* @see NormProductionServiceImpl#calculateSampleHandleOptimize(Map)
*/
@Deprecated
private List<NormProduction.NormProductionDetail> calculateSampleHandle(QueryWrapper<SampleHandle> qwHan) {
//计算处理的绩效
List<SampleHandle> sampleHandles = iSampleHandleService.list(qwHan);
List<EntrustSample> entrustSamples = iSampleHandleService.getEntrustSample();
List<NormProduction.NormProductionDetail> rts = new ArrayList<>(sampleHandles.size());
List<Integer> handleIds = new ArrayList<>();
//处理项id
sampleHandles.forEach(arg -> {
try {
handleIds.add(arg.getHandleId());
} catch (NumberFormatException ex) {
throw new RuntimeException("处理项目的id传的有问题呀!");
}
});
if (handleIds.size() == 0) {
return new ArrayList<>();
}
List<Handle> handles = iHandleService.listByIds(handleIds);
//获取每一次派发单的数据
for (SampleHandle sampleHandle : sampleHandles) {
//判断是否已经配置了
EntrustSample entrustSample = entrustSamples.stream()
.filter(arg -> arg.getDistributionId().intValue() == sampleHandle.getId())
.findFirst().orElse(null);
if (entrustSample == null) {
continue;
}
//处理项是多个处理ids 、分割
List<Integer> ids = new ArrayList<>();
try {
ids.add(sampleHandle.getHandleId());
} catch (NumberFormatException ex) {
throw new RuntimeException("处理项目的id传的有问题呀!");
}
for (Integer handleId : ids) {
String key = handleId + ":" + "0";
//判断缓存是否存在
if (!normProductionCache.containsKey(key)) {
//初始化
initNormProductionCache();
}
NormProduction normProduction = normProductionCache.get(key);
Handle handle = handles.stream()
.filter(arg -> arg.getId().intValue() == handleId)
.findFirst().orElse(null);
if (normProduction == null || handle == null) {
//如果没有配置 标准产值设置 跳过不计算
continue;
}
NormProduction.NormProductionDetail productionDetail =
initNormProductionDetail(entrustSample, normProduction, normProduction.getAnalyseRate());
productionDetail.setUserId(sampleHandle.getUserId());
productionDetail.setCheckTime(sampleHandle.getAcceptTime());
productionDetail.setDistributionId(sampleHandle.getId());
productionDetail.setAssessId(handleId);
productionDetail.setGroupTeamName(handle.getName());
rts.add(productionDetail);
}
}
return rts;
}
/**
* 计算处理派发单每条数据的标准产值
*
* @param params 统计条件
* @return 处理任务详情
*/
private List<NormProduction.NormProductionDetail> calculateSampleHandleOptimize(final Map<String, Object> params) {
if (!redisUtil.existsKey(CALCULATE_HANDLE)) {
//计算处理的绩效
List<EntrustSample> entrustSamples = iSampleHandleService.getEntrustSampleOptimize(params);
List<NormProduction.NormProductionDetail> rts = new ArrayList<>(entrustSamples.size());
List<Integer> handleIds = new ArrayList<>();
//处理项id
entrustSamples.forEach(arg -> {
Long handId = arg.getHandleId();
try {
handleIds.add(Math.toIntExact(handId));
} catch (NumberFormatException ex) {
throw new RuntimeException("处理项目的id传的有问题呀!");
}
});
if (handleIds.size() == 0) {
return new ArrayList<>();
}
List<Handle> handles = iHandleService.listByIds(handleIds);
for (EntrustSample entrustSample : entrustSamples) {
Long handId = entrustSample.getHandleId();
List<Integer> ids = new ArrayList<>(1);
try {
ids.add(Math.toIntExact(handId));
} catch (NumberFormatException ex) {
throw new RuntimeException("处理项目的id传的有问题呀!");
}
for (Integer handleId : ids) {
String key = handleId + ":" + "0";
//判断缓存是否存在
if (!normProductionCache.containsKey(key)) {
//初始化
initNormProductionCache();
}
NormProduction normProduction = normProductionCache.get(key);
Handle handle = handles.stream()
.filter(arg -> arg.getId().intValue() == handleId)
.findFirst().orElse(null);
if (normProduction == null || handle == null) {
//如果没有配置 标准产值设置 跳过不计算
continue;
}
NormProduction.NormProductionDetail productionDetail =
initNormProductionDetail(entrustSample, normProduction, normProduction.getAnalyseRate());
productionDetail.setUserId(entrustSample.getUserId());
productionDetail.setCheckTime(entrustSample.getFinishTime());
productionDetail.setDistributionId(entrustSample.getDistributionId());
productionDetail.setAssessId(handleId);
productionDetail.setGroupTeamName(handle.getName());
rts.add(productionDetail);
}
}
redisUtil.setListAll(CALCULATE_HANDLE, JSON.toJSONString(rts), 6000);
}
return JSON.parseArray(redisUtil.getString(CALCULATE_HANDLE) + "", NormProduction.NormProductionDetail.class);
}
/**
* 计算分析派发单每条数据的标准产值
* 优化版本
*
* @param param 统计条件
* @return 分析任务详情
*/
private List<NormProduction.NormProductionDetail> calculateSampleDistributionOptimize
(Map<String, Object> param) {
if (!redisUtil.existsKey(CALCULATE_DISTRIBUTION)) {
List<EntrustSample> entrustSamples = iSampleDistributionService.getSampleDistribution(param);
List<NormProduction.NormProductionDetail> rts = new ArrayList<>(entrustSamples.size());
List<Integer> groupTeamIds = entrustSamples.stream().map(EntrustSample::getTeamGroupId).collect(Collectors.toList());
if (groupTeamIds.size() == 0) {
return new ArrayList<>();
}
List<TeamGroup> teamGroups = iTeamGroupService.listByIds(groupTeamIds);
for (EntrustSample entrustSample : entrustSamples) {
TeamGroup teamGroup = teamGroups.stream()
.filter(arg -> arg.getId().intValue() == entrustSample.getTeamGroupId())
.findFirst().orElse(null);
if (entrustSample == null || teamGroup == null) {
continue;
}
String key = entrustSample.getTeamGroupId() + ":" + "1";
//判断缓存是否存在
if (!normProductionCache.containsKey(key)) {
//初始化
initNormProductionCache();
}
NormProduction normProduction = normProductionCache.get(key);
if (normProduction == null) {
//如果没有配置 标准产值设置 跳过不计算
continue;
}
NormProduction.NormProductionDetail productionDetail =
initNormProductionDetail(entrustSample, normProduction, normProduction.getAnalyseRate());
productionDetail.setUserId(entrustSample.getUserId());
productionDetail.setCheckTime(entrustSample.getFinishTime());
productionDetail.setDistributionId(entrustSample.getDistributionId());
productionDetail.setAssessId(entrustSample.getTeamGroupId());
productionDetail.setGroupTeamName(teamGroup.getName());
rts.add(productionDetail);
}
redisUtil.setListAll(CALCULATE_DISTRIBUTION, JSON.toJSONString(rts), 6000);
}
return JSON.parseArray(redisUtil.getString(CALCULATE_DISTRIBUTION) + "", NormProduction.NormProductionDetail.class);
}
/**
* 计算分析派发单每条数据的标准产值
*
* @param qwDis 统计条件
* @return 分析任务详情
* @Deprecated 已废弃, 有替代方法
* @see NormProductionServiceImpl#calculateSampleDistributionOptimize
*/
@Deprecated
private List<NormProduction.NormProductionDetail> calculateSampleDistribution
(QueryWrapper<SampleDistribution> qwDis) {
List<SampleDistribution> distributions = iSampleDistributionService.list(qwDis);
List<EntrustSample> entrustSamples = iSampleDistributionService.getEntrustSample();
List<NormProduction.NormProductionDetail> rts = new ArrayList<>(distributions.size());
List<Integer> groupTeamIds = distributions.stream().map(SampleDistribution::getTeamGroupId).collect(Collectors.toList());
if (groupTeamIds.size() == 0) {
return new ArrayList<>();
}
List<TeamGroup> teamGroups = iTeamGroupService.listByIds(groupTeamIds);
//获取每一次派发单的数据
for (SampleDistribution distribution : distributions) {
//判断是否已经配置了
EntrustSample entrustSample = entrustSamples.stream()
.filter(arg -> arg.getDistributionId().intValue() == distribution.getId())
.findFirst().orElse(null);
TeamGroup teamGroup = teamGroups.stream()
.filter(arg -> arg.getId().intValue() == distribution.getTeamGroupId())
.findFirst().orElse(null);
if (entrustSample == null || teamGroup == null) {
continue;
}
String key = distribution.getTeamGroupId() + ":" + "1";
//判断缓存是否存在
if (!normProductionCache.containsKey(key)) {
//初始化
initNormProductionCache();
}
NormProduction normProduction = normProductionCache.get(key);
if (normProduction == null) {
//如果没有配置 标准产值设置 跳过不计算
continue;
}
NormProduction.NormProductionDetail productionDetail =
initNormProductionDetail(entrustSample, normProduction, normProduction.getAnalyseRate());
productionDetail.setUserId(distribution.getUserId());
productionDetail.setCheckTime(distribution.getAcceptTime());
productionDetail.setDistributionId(distribution.getId());
productionDetail.setAssessId(distribution.getTeamGroupId());
productionDetail.setGroupTeamName(teamGroup.getName());
rts.add(productionDetail);
}
return rts;
}
/**
* 初始化产值明细
*
* @param entrustSample 分样任务
* @param normProduction 标准产值配置表
* @return 标准产值明细
*/
private NormProduction.NormProductionDetail initNormProductionDetail(
EntrustSample entrustSample, NormProduction normProduction, Double rate) {
NormProduction.NormProductionDetail productionDetail =
new NormProduction.NormProductionDetail();
productionDetail.setAnalyseRate(normProduction.getAnalyseRate());
productionDetail.setAssessRate(normProduction.getAssessRate());
productionDetail.setSeparateRate(normProduction.getSeparateRate());
productionDetail.setReportedResultRate(normProduction.getReportedResultRate());
productionDetail.setAssessId(normProduction.getAssessId());
productionDetail.setEntrustId(entrustSample.getEntrustId());
productionDetail.setProjectName(entrustSample.getProjectName());
productionDetail.setSampleName(entrustSample.getSampleName());
productionDetail.setSampleId(entrustSample.getSampleId());
productionDetail.setEntrustCode(entrustSample.getEntrustCode());
productionDetail.setWorkTimeCoefficient(calculateWorkTimeCoefficient(normProduction,
rate));
return productionDetail;
}
/**
* 初始化标准产值缓存
*/
private void initNormProductionCache() {
QueryWrapper<NormProduction> qw = new QueryWrapper<>();
qw.eq("status", 1);
List<NormProduction> list = this.list(qw);
for (NormProduction normProduction : list) {
String key = normProduction.getAssessId() + ":" + normProduction.getType();
normProductionCache.put(key, normProduction);
}
}
/**
* 计算标准产值的工时标准系数 plan
* 额定工日*建议系数/报出对应分析结果*考核工值*分析占比
*
* @param normProduction 标准产值配置对象 如:六元素
* @param rate 具体的操作占比 如:统计分析 85%
* @return BigDecimal
*/
private BigDecimal calculateWorkTimeCoefficient(NormProduction normProduction, Double rate) {
//计算出工时标准系数:
//额定工日*建议系数/报出对应分析结果*考核工值*分析占比
BigDecimal quotaDayBig = BigDecimal.valueOf(normProduction.getQuotaDay());
BigDecimal coefficientBig = BigDecimal.valueOf(normProduction.getCoefficient());
BigDecimal reportedAnalyseRtsBig = BigDecimal.valueOf(normProduction.getReportedAnalyseResult());
BigDecimal assessValueBig = BigDecimal.valueOf(normProduction.getAssessValue());
BigDecimal analyseRateBig = BigDecimal.valueOf(rate);
return quotaDayBig.multiply(coefficientBig)
.divide(reportedAnalyseRtsBig, 6, RoundingMode.HALF_DOWN)
.multiply(assessValueBig).multiply(analyseRateBig)
.setScale(6, RoundingMode.HALF_DOWN);
}
}
......@@ -6,31 +6,22 @@ import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.wise.sc.cement.business.entity.*;
import cn.wise.sc.cement.business.mapper.EntrustMapper;
import cn.wise.sc.cement.business.mapper.PrecipriceMapper;
import cn.wise.sc.cement.business.mapper.ProjectMapper;
import cn.wise.sc.cement.business.mapper.SampleMapper;
import cn.wise.sc.cement.business.mapper.*;
import cn.wise.sc.cement.business.model.BaseResponse;
import cn.wise.sc.cement.business.model.LoginUser;
import cn.wise.sc.cement.business.model.PageQuery;
import cn.wise.sc.cement.business.model.vo.EntrustVo;
import cn.wise.sc.cement.business.model.vo.NormProductionStatisticsVo;
import cn.wise.sc.cement.business.model.vo.ProductionVo;
import cn.wise.sc.cement.business.model.vo.WorkloadStatisticsVo;
import cn.wise.sc.cement.business.service.IEntrustService;
import cn.wise.sc.cement.business.service.IHandleService;
import cn.wise.sc.cement.business.service.INonStandardApplyService;
import cn.wise.sc.cement.business.service.INonStandardValueService;
import cn.wise.sc.cement.business.service.INormProductionService;
import cn.wise.sc.cement.business.service.IPrecipriceService;
import cn.wise.sc.cement.business.service.ISampleDistributionService;
import cn.wise.sc.cement.business.service.ISampleService;
import cn.wise.sc.cement.business.service.ISysGroupService;
import cn.wise.sc.cement.business.service.ISysPostService;
import cn.wise.sc.cement.business.service.ISysUserService;
import cn.wise.sc.cement.business.service.ITeamGroupService;
import cn.wise.sc.cement.business.service.*;
import cn.wise.sc.cement.business.util.ExcelUtil;
import cn.wise.sc.cement.business.util.PageUtil;
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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
......@@ -66,58 +57,41 @@ import java.util.stream.Collectors;
@Service
public class PrecipriceServiceImpl extends ServiceImpl<PrecipriceMapper, Preciprice> implements IPrecipriceService {
final
EntrustMapper iEntrustService;
final
ISampleService iSampleService;
final
INormProductionService iNormProductionService;
final
ISysUserService iSysUserService;
final
ISysGroupService iSysGroupService;
final
ITeamGroupService iTeamGroupService;
final
IHandleService iHandleService;
final
ISysPostService iSysPostService;
final
INonStandardValueService iNonStandardValueService;
final
INonStandardApplyService iNonStandardApplyService;
final
ISampleDistributionService iSampleDistributionService;
@Autowired
private ISysUserService userService;
@Resource
PrecipriceMapper precipriceMapper;
@Resource
private SysUserMapper userMapper;
@Resource
private SysGroupMapper groupMapper;
@Resource
private EntrustMapper entrustMapper;
@Resource
private SampleMapper sampleMapper;
@Resource
private NormProductionMapper normProductionMapper;
@Resource
private TeamMapper teamMapper;
@Resource
private TeamGroupMapper teamGroupMapper;
@Resource
private SampleDistributionMapper distributionMapper;
@Resource
private NonStandardApplyMapper nonStandardApplyMapper;
@Autowired
private ISysUserService userService;
private INonStandardValueService nonStandardValueService;
public PrecipriceServiceImpl(EntrustMapper iEntrustService,
ISampleService iSampleService,
INormProductionService iNormProductionService,
ISysUserService iSysUserService,
ISysGroupService iSysGroupService,
ITeamGroupService iTeamGroupService,
IHandleService iHandleService,
ISysPostService iSysPostService,
INonStandardValueService iNonStandardValueService,
INonStandardApplyService iNonStandardApplyService,
ISampleDistributionService iSampleDistributionService) {
this.iEntrustService = iEntrustService;
this.iSampleService = iSampleService;
this.iNormProductionService = iNormProductionService;
this.iSysUserService = iSysUserService;
this.iSysGroupService = iSysGroupService;
this.iTeamGroupService = iTeamGroupService;
this.iHandleService = iHandleService;
this.iSysPostService = iSysPostService;
this.iNonStandardValueService = iNonStandardValueService;
this.iNonStandardApplyService = iNonStandardApplyService;
this.iSampleDistributionService = iSampleDistributionService;
}
/**
* 计算产值
* @param userId
* @param entrustId
* @param targetId
* @param type
* @param sampleId
* @param isUrgent
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class, propagation = Propagation.NESTED)
......@@ -127,22 +101,22 @@ public class PrecipriceServiceImpl extends ServiceImpl<PrecipriceMapper, Precipr
Assert.notNull(userId, "用户id不能为空!");
Assert.notNull(entrustId, "项目id不能为空!");
Assert.notNull(targetId, "处理项id不能为空!");
Assert.notNull(sampleId, "样品id不能为空!");
Assert.notNull(type, "处理项类型不能为空!");
//获取项目编号和名字
Entrust entrust = iEntrustService.selectById(entrustId);
Entrust entrust = entrustMapper.selectById(entrustId);
if (BeanUtil.isEmpty(entrust)) {
log.debug("产值记录新增失败,项目没找到!");
throw new IllegalArgumentException("无效的项目id!");
}
Preciprice preciprice = new Preciprice();
preciprice.setEntrustId(entrust.getId());
preciprice.setProjectName(entrust.getProjectName());
preciprice.setProjectCode(entrust.getProjectCode());
preciprice.setEntrustCode(entrust.getEntrustCode());
preciprice.setEntrustName(entrust.getProjectName());
preciprice.setIsUrgent(isUrgent ? 1 : 0);
//获取样品信息
Sample sample = iSampleService.getById(sampleId);
Sample sample = sampleMapper.selectById(sampleId);
if (BeanUtil.isEmpty(sample)) {
log.debug("产值记录新增失败,项目没找到!");
throw new IllegalArgumentException("无效的项目id!");
......@@ -152,10 +126,12 @@ public class PrecipriceServiceImpl extends ServiceImpl<PrecipriceMapper, Precipr
//获取产值信息
QueryWrapper<NormProduction> queryWrapper = new QueryWrapper<>();
if(targetId != null){
queryWrapper.eq("assess_id", targetId);
}
queryWrapper.eq("type", type);
queryWrapper.eq("status", 1);
NormProduction normProduction = iNormProductionService.getOne(queryWrapper);
NormProduction normProduction = normProductionMapper.selectOne(queryWrapper);
if (BeanUtil.isEmpty(normProduction)) {
log.debug("产值记录新增失败,产值信息没找到!");
......@@ -170,21 +146,28 @@ public class PrecipriceServiceImpl extends ServiceImpl<PrecipriceMapper, Precipr
preciprice.setCreateTime(DateUtil.date().getTime());
preciprice.setSeparateRate(BigDecimal.valueOf(normProduction.getSeparateRate()));
preciprice.setQuotaDay(BigDecimal.valueOf(normProduction.getQuotaDay()));
if (type == 1) {
//产值计算算法
if (type == 0) {
if (isUrgent) {
preciprice.setPreciprice(new BigDecimal(3).subtract(calculateWorkTimeCoefficient(normProduction, normProduction.getAnalyseRate())));
preciprice.setPreciprice(new BigDecimal(3).multiply(calculateWorkTimeCoefficient(normProduction, normProduction.getAnalyseRate())));
} else {
preciprice.setPreciprice(calculateWorkTimeCoefficient(normProduction, normProduction.getAnalyseRate()));
}
}else if(type == 1){
if (isUrgent) {
preciprice.setPreciprice(new BigDecimal(3).multiply(calculateWorkTimeCoefficient(normProduction, normProduction.getAnalyseRate())));
} else {
preciprice.setPreciprice(calculateWorkTimeCoefficient(normProduction, normProduction.getAnalyseRate()));
}
}else if(type == 2){
if (isUrgent) {
preciprice.setPreciprice(new BigDecimal(3).subtract(calculateWorkTimeCoefficient(normProduction, normProduction.getAnalyseRate())));
preciprice.setPreciprice(new BigDecimal(3).multiply(calculateWorkTimeCoefficient(normProduction, normProduction.getAnalyseRate())));
} else {
preciprice.setPreciprice(calculateWorkTimeCoefficient(normProduction, normProduction.getAnalyseRate()));
}
}
//获取用户职位和账号
SysUser sysUser = iSysUserService.getById(userId);
SysUser sysUser = userMapper.selectById(userId);
if (BeanUtil.isEmpty(sysUser)) {
log.debug("产值记录新增失败,用户没找到!");
throw new IllegalArgumentException("无效的用户id!");
......@@ -192,7 +175,7 @@ public class PrecipriceServiceImpl extends ServiceImpl<PrecipriceMapper, Precipr
preciprice.setUserId(sysUser.getId());
preciprice.setUserName(sysUser.getName());
preciprice.setSex(sysUser.getSex());
SysGroup sysGroup = iSysGroupService.getById(sysUser.getGroupId());
SysGroup sysGroup = groupMapper.selectById(sysUser.getGroupId());
if (BeanUtil.isEmpty(sysGroup)) {
log.debug("产值记录新增失败,用户所在部门未找到!");
throw new IllegalArgumentException("用户所在部门需要设置!");
......@@ -201,12 +184,14 @@ public class PrecipriceServiceImpl extends ServiceImpl<PrecipriceMapper, Precipr
preciprice.setGroupId(sysGroup.getId());
//获取检测组名
if (type == 1) {
TeamGroup teamGroup = iTeamGroupService.getById(targetId);
if (type == 0) {
preciprice.setGroupTeamName("处理项");
} else if(type == 1) {
TeamGroup teamGroup = teamGroupMapper.selectById(targetId);
preciprice.setGroupTeamName(teamGroup.getName());
} else {
Handle handle = iHandleService.getById(targetId);
preciprice.setGroupTeamName(handle.getName());
}else if(type == 2) {
Team team = teamMapper.selectById(targetId);
preciprice.setGroupTeamName(team.getName());
}
preciprice.setTargetId(targetId);
preciprice.setType(type);
......@@ -219,130 +204,228 @@ public class PrecipriceServiceImpl extends ServiceImpl<PrecipriceMapper, Precipr
}
}
/**
* 产值统计-标准产值-分页列表
* @param pageQuery
* @param startDate
* @param endDate
* @param userName
* @return
*/
public BaseResponse<IPage<NormProductionStatisticsVo>> normProductionStatistics(PageQuery pageQuery, String startDate, String endDate,String userName) {
LoginUser loginUser = userService.getLoginUser();
if (loginUser == null) {
return BaseResponse.noLogin("请登录账号");
}
@Override
public BaseResponse<List<NormProductionStatistics>> normProductionStatistics(Long start, Long end, String name, Integer groupId) {
Map<String, Object> params = new HashMap<>();
params.put("startDate", StrUtil.isNotBlank(startDate)?DateUtil.parseDate(startDate).getTime():null);
params.put("endDate", StrUtil.isNotBlank(endDate)?DateUtil.parseDate(endDate).getTime():null);
params.put("userName", userName);
//只有管理员角色的用户可以查看所有人的产值,其他人只能查看自己的产值
if(loginUser.getRoleList().getId() != 1){
params.put("userId", loginUser.getId());
}
Page<NormProductionStatisticsVo> page = new Page<>(pageQuery.getPageNo(), pageQuery.getPageSize());
IPage<NormProductionStatisticsVo> pages = precipriceMapper.getStatisticsPage(page, params);
return BaseResponse.okData(pages);
}
/**
* 产值统计-标准产值-列表
* @param startDate
* @param endDate
* @param userName
* @return
*/
public BaseResponse<List<NormProductionStatisticsVo>> statisticsList(String startDate, String endDate,String userName) {
LoginUser loginUser = userService.getLoginUser();
if (loginUser == null) {
return BaseResponse.noLogin("请登录账号");
}
//标准产值
Map<String, Object> params = new HashMap<>();
params.put("userName", userName);
params.put("startDate", StrUtil.isNotBlank(startDate)?DateUtil.parseDate(startDate).getTime():null);
params.put("endDate", StrUtil.isNotBlank(endDate)?DateUtil.parseDate(endDate).getTime():null);
//只有管理员角色的用户可以查看所有人的产值,其他人只能查看自己的产值
Integer userobjId = null;
if(loginUser.getRoleList().getId() != 1){
userobjId = loginUser.getId();
params.put("userId", loginUser.getId());
}
List<NormProductionStatisticsVo> productionStatistics = precipriceMapper.getStatisticsList(params);
return BaseResponse.okData(productionStatistics);
}
//统计分样处理的详情
List<NormProduction.NormProductionDetail> normProductionDetails =
normProductionDetails(userobjId, start, end);
if (normProductionDetails.size() == 0) {
BaseResponse<List<NormProductionStatistics>> rts = BaseResponse.okData(null);
rts.setData(new ArrayList<>());
return rts;
/**
* 产值统计-标准产值-个人详情
* @param pageQuery
* @param startDate
* @param endDate
* @param userId
* @return
*/
@Override
public BaseResponse<IPage<NormProduction.NormProductionUserDetail>>normProductionDetails(PageQuery pageQuery, String startDate, String endDate, Integer userId) {
if(userId == null ){
return BaseResponse.errorMsg("参数错误");
}
//
Map<Integer, BigDecimal> coefficientMap = new HashMap<>(normProductionDetails.size());
normProductionDetails
.forEach(arg -> {
Integer userId = arg.getUserId();
//不存在 添加
if (!coefficientMap.containsKey(userId)) {
coefficientMap.put(userId, arg.getWorkTimeCoefficient());
} else {
BigDecimal bigDecimal = coefficientMap.get(userId);
BigDecimal newWorkTime = arg.getWorkTimeCoefficient().add(bigDecimal);
coefficientMap.put(userId, newWorkTime);
SysUser sysUser = userService.getById(userId);
if(sysUser == null){
return BaseResponse.errorMsg("信息错误");
}
});
List<NormProductionStatistics> rts = new ArrayList<>();
Set<Integer> userIds = coefficientMap.keySet();
QueryWrapper<SysUser> qw = new QueryWrapper<>();
qw.in("id", userIds);
List<SysUser> users = iSysUserService.list(qw);
List<SysPost> sysPosts = iSysPostService.list();
List<SysGroup> sysGroups = iSysGroupService.list();
for (Integer userId : coefficientMap.keySet()) {
SysUser sysUser = users.stream()
.filter(arg -> arg.getId().intValue() == userId)
.findFirst().orElse(null);
SysGroup sysGroup = sysGroups.stream().filter(arg -> arg.getId().intValue() == sysUser.getGroupId())
.findFirst().orElse(null);
if (sysUser == null) {
continue;
}
if (sysGroup == null) {
log.debug("用户分组未设置!关联用户部门失败!");
continue;
}
NormProductionStatistics productionStatistics = new NormProductionStatistics();
productionStatistics.setAccount(sysUser.getUsername());
productionStatistics.setCoefficient(coefficientMap.get(userId).doubleValue());
productionStatistics.setTime("/");
productionStatistics.setCount(normProductionDetails.stream()
.filter(arg -> arg.getUserId().intValue() == sysUser.getId())
.count());
productionStatistics.setPosition(sysUser.getQualifications());
if (start != null && end != null) {
DateTime startTime = DateUtil.date(start);
DateTime endTime = DateUtil.date(end);
productionStatistics.setTime(startTime.toDateStr() + "-" + endTime.toDateStr());
}
productionStatistics.setSex(sysUser.getSex() == 0 ? "女" : "男");
productionStatistics.setUserId(sysUser.getId() + "");
productionStatistics.setUserName(sysUser.getName());
productionStatistics.setGroupId(sysUser.getGroupId());
productionStatistics.setGroupName(sysGroup.getName());
SysPost sysPost = sysPosts.stream()
.filter(arg -> arg.getId().intValue() == sysUser.getPostId()).
findFirst().orElse(null);
productionStatistics.setPosition(sysPost == null ? "职务一" : sysPost.getName());
productionStatistics.setGroupName(sysGroup.getName());
rts.add(productionStatistics);
}
//过滤名字
if (StrUtil.isNotBlank(name)) {
List<NormProductionStatistics> collect = rts.stream().filter(arg -> arg.getUserName().contains(name)).collect(Collectors.toList());
return BaseResponse.okData(collect);
}
//过滤部门id
if (groupId != null) {
List<NormProductionStatistics> collect = rts.stream().filter(arg -> arg.getGroupId().equals(groupId)).collect(Collectors.toList());
return BaseResponse.okData(collect);
}
return BaseResponse.okData(rts);
QueryWrapper<Preciprice> qw = new QueryWrapper<>();
if (StrUtil.isNotBlank(startDate)) {
qw.gt("create_time", DateUtil.parseDate(startDate).getTime());
}
if (StrUtil.isNotBlank(endDate)) {
qw.le("create_time", DateUtil.parseDate(endDate).getTime());
}
if (!BeanUtil.isEmpty(userId)) {
qw.eq("user_id", userId);
}
qw.eq("status", 1);
qw.orderByDesc("create_time");
List<Preciprice> list = this.list(qw);
List<NormProduction.NormProductionUserDetail> rts = new ArrayList<>(list.size());
//处理项
List<Preciprice> handlelist =list.stream().filter(arg ->(arg.getType()==0)).collect(Collectors.toList());
if(handlelist != null && handlelist.size()>0){
NormProduction.NormProductionUserDetail UserDetailRts = new NormProduction.NormProductionUserDetail();
UserDetailRts.setType(0);
UserDetailRts.setUserName(sysUser.getName());
UserDetailRts.setObjId(null);
UserDetailRts.setObjName("处理项");
UserDetailRts.setCountNums(handlelist.size());
UserDetailRts.setCountPricel(handlelist.stream().map(Preciprice::getPreciprice).reduce(BigDecimal.ZERO,BigDecimal::add));
rts.add(UserDetailRts);
}
//检测组
List<Preciprice> teamGrouplist = list.stream().filter(arg ->(arg.getType()==1)).collect(Collectors.toList());
if(teamGrouplist != null && teamGrouplist.size()>0){
Map<Integer, List<Preciprice>> mapByGroupId = teamGrouplist.stream().collect(Collectors.groupingBy(Preciprice::getTargetId, Collectors.toList()));
for(Map.Entry<Integer, List<Preciprice>> entry : mapByGroupId.entrySet()){
NormProduction.NormProductionUserDetail UserDetailRts = new NormProduction.NormProductionUserDetail();
UserDetailRts.setType(1);
UserDetailRts.setUserName(sysUser.getName());
UserDetailRts.setObjId(entry.getKey());
UserDetailRts.setObjName(entry.getValue().get(0).getGroupTeamName());
UserDetailRts.setCountNums(entry.getValue().size());
UserDetailRts.setCountPricel(entry.getValue().stream().map(Preciprice::getPreciprice).reduce(BigDecimal.ZERO,BigDecimal::add));
rts.add(UserDetailRts);
}
}
//检测项
List<Preciprice> teamlist = list.stream().filter(arg ->(arg.getType()==2)).collect(Collectors.toList());
if(teamlist != null && teamlist.size()>0){
Map<Integer, List<Preciprice>> mapByTeamId = teamGrouplist.stream().collect(Collectors.groupingBy(Preciprice::getTargetId, Collectors.toList()));
for(Map.Entry<Integer, List<Preciprice>> entry : mapByTeamId.entrySet()){
NormProduction.NormProductionUserDetail UserDetailRts = new NormProduction.NormProductionUserDetail();
UserDetailRts.setType(2);
UserDetailRts.setUserName(sysUser.getName());
UserDetailRts.setObjId(entry.getKey());
UserDetailRts.setObjName(entry.getValue().get(0).getGroupTeamName());
UserDetailRts.setCountNums(entry.getValue().size());
UserDetailRts.setCountPricel(entry.getValue().stream().map(Preciprice::getPreciprice).reduce(BigDecimal.ZERO,BigDecimal::add));
rts.add(UserDetailRts);
}
}
if (rts!=null && rts.size() > 0) {
Page<NormProduction.NormProductionUserDetail> rts2 = PageUtil.listConvertToPage(rts, pageQuery);
return BaseResponse.okData(rts2);
}
return BaseResponse.okData(new Page<>());
}
/**
* 产值统计-标准产值-个人详情-检测项目详情
* @param pageQuery
* @param startDate
* @param endDate
* @param userId
* @param type
* @param objId
* @return
*/
@Override
public List<NormProduction.NormProductionDetail>
normProductionDetails(Integer userId, Long startTime, Long endTime) {
public BaseResponse<IPage<NormProduction.NormProductionDetail>>normProductionSpecificDetails(PageQuery pageQuery,
String startDate, String endDate, Integer userId, Integer type, Integer objId) {
if(userId == null ){
return BaseResponse.errorMsg("参数错误");
}
if(type == null ){
return BaseResponse.errorMsg("请传入类型");
}
SysUser sysUser = userService.getById(userId);
if(sysUser == null){
return BaseResponse.errorMsg("信息错误");
}
QueryWrapper<Preciprice> qw = new QueryWrapper<>();
if (!BeanUtil.isEmpty(startTime)) {
qw.gt("create_time", startTime);
if (StrUtil.isNotBlank(startDate)) {
qw.gt("create_time", DateUtil.parseDate(startDate).getTime());
}
if (!BeanUtil.isEmpty(endTime)) {
qw.le("create_time", endTime);
if (StrUtil.isNotBlank(endDate)) {
qw.le("create_time", DateUtil.parseDate(endDate).getTime());
}
if (!BeanUtil.isEmpty(userId)) {
qw.eq("user_id", userId);
}
if (!BeanUtil.isEmpty(type)) {
qw.eq("type", type);
}
if(type == 0){
qw.eq("group_team_name", "处理项");
}else{
qw.eq("target_id", objId);
}
qw.eq("status", 1);
qw.orderByDesc("create_time");
List<Preciprice> list = this.list(qw);
List<NormProduction.NormProductionDetail> rts = new ArrayList<>(list.size());
for (Preciprice preciprice : list) {
NormProduction.NormProductionDetail detail = preciprice2NormDetail(preciprice);
rts.add(detail);
for(Preciprice pp : list){
NormProduction.NormProductionDetail UserDetailRts = new NormProduction.NormProductionDetail();
UserDetailRts.setUserName(pp.getUserName());
UserDetailRts.setObjName(pp.getGroupTeamName());
UserDetailRts.setProjectName(pp.getProjectName());
UserDetailRts.setProjectCode(pp.getProjectCode());
UserDetailRts.setEntrustCode(pp.getEntrustCode());
UserDetailRts.setCheckTime(LocalDateTime.ofInstant(Instant.ofEpochMilli(pp.getCreateTime()), ZoneId.systemDefault()));
UserDetailRts.setCountPricel(pp.getPreciprice());
rts.add(UserDetailRts);
}
return rts;
if (rts!=null && rts.size() > 0) {
Page<NormProduction.NormProductionDetail> rts2 = PageUtil.listConvertToPage(rts, pageQuery);
return BaseResponse.okData(rts2);
}
return BaseResponse.okData(new Page<>());
}
/**
* 产值统计-产值统计-总产值统计
* @param name 用户
* @param start 开始时间
* @param end 结束时间
* @param groupId
* @return
*/
@Override
public List<ProductionVo> production(String name, Long start, Long end, Integer groupId) {
Date startDate = null;
......@@ -355,13 +438,20 @@ public class PrecipriceServiceImpl extends ServiceImpl<PrecipriceMapper, Precipr
}
//非标准产值
List<NonStandardValue> nonStandardValues = iNonStandardValueService.nonValue(startDate, endDate, groupId, name).getData();
List<NonStandardValue> nonStandardValues = nonStandardValueService.nonValue(startDate, endDate, groupId, name).getData();
//标准产值
List<NormProductionStatistics> productionStatistics = this.normProductionStatistics(start, end, name, groupId).getData();
Map<String, Object> params = new HashMap<>();
params.put("userName", name);
params.put("startDate", start);
params.put("endDate", end);
params.put("groupId", groupId);
List<NormProductionStatisticsVo> productionStatistics = precipriceMapper.getStatisticsList(params);
//以userId找关系
Set<String> userIds = new HashSet<>();
nonStandardValues.forEach(arg -> userIds.add(arg.getUserId() + ""));
nonStandardValues.forEach(arg -> userIds.add(arg.getUserId().toString()));
productionStatistics.forEach(arg -> userIds.add(arg.getUserId()));
List<ProductionVo> rts = new ArrayList<>(userIds.size());
userIds.forEach(arg -> {
ProductionVo productionVo = new ProductionVo();
......@@ -371,229 +461,29 @@ public class PrecipriceServiceImpl extends ServiceImpl<PrecipriceMapper, Precipr
if (opt.getUserId().equals(arg)) {
productionVo.setProductionValue(opt.getCoefficient());
productionVo.setUserName(opt.getUserName());
productionVo.setPosition(opt.getPosition());
productionVo.setAccount(opt.getAccount());
productionVo.setGroupId(opt.getGroupId());
productionVo.setGroupName(opt.getGroupName());
productionVo.setSex(opt.getSex());
}
});
//找到标准产值里面的数据
//找到非标产值里面的数据
nonStandardValues.forEach(opt -> {
if (arg.equals(opt.getUserId() + "")) {
if (arg.equals(opt.getUserId())) {
productionVo.setNonProductionValue(opt.getFinalValue());
}
});
rts.add(productionVo);
});
//处理非标准产值没有用名职位信息
QueryWrapper<SysUser> qw = new QueryWrapper<>();
qw.in("id", userIds);
if (CollectionUtil.isEmpty(userIds)) {
return null;
}
List<SysUser> users = iSysUserService.list(qw);
List<SysPost> sysPosts = iSysPostService.list();
List<SysGroup> sysGroups = iSysGroupService.list();
Date finalStartDate = startDate;
Date finalEndDate = endDate;
rts.forEach(arg -> {
arg.setTime(finalStartDate == null ? "/" : DateUtil.format(finalStartDate, "yyyy-MM-dd") + "--" + DateUtil.format(finalEndDate, "yyyy-MM-dd"));
if (StrUtil.isBlank(arg.getUserName())) {
//关联用户信息
users.stream().filter(opt -> arg.getUserId().equals(opt.getId() + "")).findFirst()
.ifPresent(opt -> {
arg.setUserName(opt.getName());
arg.setAccount(opt.getUsername());
arg.setPositionId(opt.getPostId());
arg.setGroupId(opt.getGroupId());
});
//关联职务
sysPosts.stream().filter(opt -> arg.getPositionId().intValue() == opt.getId())
.findFirst()
.ifPresent(opt -> arg.setPosition(opt.getName()));
sysGroups.stream().filter(opt -> arg.getGroupId().intValue() == opt.getId())
.findFirst()
.ifPresent(opt -> arg.setGroupName(opt.getName()));
}
arg.setProductionTotalValue(arg.getNonProductionValue() + arg.getProductionValue());
});
//过滤名字
if (StrUtil.isNotBlank(name)) {
return rts.stream().filter(arg -> arg.getUserName().contains(name))
.collect(Collectors.toList());
}
//过滤部门id
if (groupId != null) {
return rts.stream().filter(arg -> arg.getGroupId().equals(groupId))
.collect(Collectors.toList());
}
return rts;
}
@Override
public void exportNormProductionStatistics(Long start, Long end, String name, Integer groupId, HttpServletResponse response) {
BaseResponse<List<NormProductionStatistics>> listBaseResponse = normProductionStatistics(start, end, name, groupId);
if (listBaseResponse.getCode() == 200) {
List<NormProductionStatistics> data = listBaseResponse.getData();
if (CollectionUtil.isNotEmpty(data)) {
String[] headers = new String[10];
headers[0] = "用户编号";
headers[1] = "用户名";
headers[2] = "账号";
headers[3] = "性别";
headers[4] = "职务";
headers[5] = "统计时间";
headers[6] = "检测项目数";
headers[7] = "产值绩效";
headers[8] = "部门id";
headers[9] = "部门名";
List<Object[]> exportData = new ArrayList<>(data.size());
for (NormProductionStatistics productionStatistics : data) {
Object[] objs = new Object[10];
objs[0] = productionStatistics.getUserId();
objs[1] = productionStatistics.getUserName();
objs[2] = productionStatistics.getAccount();
objs[3] = productionStatistics.getSex();
objs[4] = productionStatistics.getPosition();
objs[5] = productionStatistics.getTime();
objs[6] = productionStatistics.getCount();
objs[7] = productionStatistics.getCoefficient();
objs[8] = productionStatistics.getGroupId();
objs[9] = productionStatistics.getGroupName();
exportData.add(objs);
}
ExcelUtil.excelExport(
"标准产值统计", headers,
exportData, response);
}
}
}
@Override
public void exportNormProductionDetail(Integer userId, Long startTime, Long endTime, HttpServletResponse response) {
List<NormProduction.NormProductionDetail> normProductionDetails = normProductionDetails(userId, startTime, endTime);
if (CollectionUtil.isNotEmpty(normProductionDetails)) {
String[] headers = new String[13];
headers[0] = "序号";
headers[1] = "名字";
headers[2] = "检测项目";
headers[3] = "所属项目";
headers[4] = "项目编号";
headers[5] = "检测时间";
headers[6] = "分析占比";
headers[7] = "分样占比";
headers[8] = "校核占比";
headers[9] = "报结果占比";
headers[10] = "合计";
List<Object[]> exportData = new ArrayList<>(normProductionDetails.size());
int count = 0;
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日 hh:mm:ss");
for (NormProduction.NormProductionDetail target : normProductionDetails) {
Object[] objs = new Object[13];
objs[0] = count++;
objs[1] = target.getUserName();
objs[2] = target.getGroupTeamName();
objs[3] = target.getProjectName();
objs[4] = target.getEntrustCode();
objs[5] = target.getCheckTime() == null ? "/" : target.getCheckTime().format(timeFormatter);
objs[6] = target.getAnalyseRate();
objs[7] = target.getSeparateRate();
objs[8] = target.getAssessRate();
objs[9] = target.getReportedResultRate();
objs[10] = target.getWorkTimeCoefficient();
exportData.add(objs);
}
ExcelUtil.excelExport("标准产值详情—" + normProductionDetails.get(0).getUserName(), headers, exportData, response);
}
}
@Override
public void exportProduction(String name, Long startTime, Long endTime, Integer groupId, HttpServletResponse response) {
List<ProductionVo> data = production(name, startTime, endTime, groupId);
if (CollectionUtil.isNotEmpty(data)) {
String[] headers = new String[10];
headers[0] = "序号";
headers[1] = "姓名";
headers[2] = "账户";
headers[3] = "职务";
headers[4] = "统计时间";
headers[5] = "标准产值";
headers[6] = "非标准产值";
headers[7] = "产值统计";
headers[8] = "部门id";
headers[9] = "部门名";
List<Object[]> exportData = new ArrayList<>(data.size());
int count = 0;
for (ProductionVo target : data) {
Object[] objs = new Object[10];
objs[0] = count++;
objs[1] = target.getUserName();
objs[2] = target.getAccount();
objs[3] = target.getPosition();
objs[4] = target.getTime();
objs[5] = target.getProductionValue();
objs[6] = target.getNonProductionValue();
objs[7] = target.getProductionTotalValue();
objs[8] = target.getGroupId();
objs[9] = target.getGroupName();
exportData.add(objs);
}
ExcelUtil.excelExport("产值统计", headers, exportData, response);
}
}
@Override
public List<WorkloadStatisticsVo> workloadStatistics(Date startTime, Date endTime, Integer userId) {
long start = getDefaultStart(startTime == null ? 0 : startTime.getTime());
long end = getDefaultEnd(endTime.getTime());
Map<String, Integer> map1 = initMonthMoneyMap(start, end);
Map<String, Integer> map2 = initMonthMoneyMap(start, end);
QueryWrapper<SampleDistribution> qw = new QueryWrapper<>();
if (startTime != null) {
qw.ge("finish_time", DateUtil.format(DateUtil.date(start), "yyyy-MM-dd"));
}
if (userId != null && userId != 0) {
qw.eq("user_id", userId);
}
qw.le("finish_time", DateUtil.format(DateUtil.date(end), "yyyy-MM-dd"));
qw.eq("status", 2);
List<SampleDistribution> sampleDistributions = iSampleDistributionService.list(qw);
QueryWrapper<NonStandardApply> qwA = new QueryWrapper<>();
if (startTime != null) {
qwA.ge("start_time", DateUtil.format(DateUtil.date(start), "yyyy-MM-dd"));
}
if (userId != null && userId != 0) {
qwA.eq("user_id", userId);
}
qwA.le("start_time", DateUtil.format(DateUtil.date(end), "yyyy-MM-dd"));
qwA.eq("status", 2);
List<NonStandardApply> nonStandardApplies = iNonStandardApplyService.list(qwA);
for (SampleDistribution sampleDistribution : sampleDistributions) {
addCount(sampleDistribution.getFinishTime(), map1);
}
for (NonStandardApply nonStandardApply : nonStandardApplies) {
addCount(nonStandardApply.getStartTime(), map2);
}
WorkloadStatisticsVo workloadStatisticsVo = new WorkloadStatisticsVo();
workloadStatisticsVo.setType(0);
workloadStatisticsVo.setMap(map1);
WorkloadStatisticsVo workloadStatisticsVo2 = new WorkloadStatisticsVo();
workloadStatisticsVo2.setType(1);
workloadStatisticsVo2.setMap(map2);
List<WorkloadStatisticsVo> rts = new ArrayList<>(2);
rts.add(workloadStatisticsVo);
rts.add(workloadStatisticsVo2);
return rts;
}
/**
* 根据报告id更新
* @param entrustId
* @return
*/
@Override
public boolean updateStatusByEntrustId(Integer entrustId) {
cn.hutool.core.lang.Assert.notNull(entrustId, "报告id不能为空!");
......@@ -609,104 +499,6 @@ public class PrecipriceServiceImpl extends ServiceImpl<PrecipriceMapper, Precipr
}
private NormProduction.NormProductionDetail preciprice2NormDetail(Preciprice preciprice) {
NormProduction.NormProductionDetail rts = new NormProduction.NormProductionDetail();
BeanUtil.copyProperties(preciprice, rts);
//todo 暂时去掉本所编号
/*if(rts.getSampleId() != null){
Sample sample = sampleMapper.selectById(rts.getSampleId());
if(sample != null){
rts.setCementCode(sample.getCementCode());
}
}*/
//todo 增加项目信息
rts.setProjectName(preciprice.getEntrustName());
rts.setAssessId(preciprice.getTargetId());
rts.setWorkTimeCoefficient(preciprice.getPreciprice());
rts.setCheckTime(getDateTimeOfTimestamp(preciprice.getCreateTime()));
return rts;
}
public static LocalDateTime getDateTimeOfTimestamp(long timestamp) {
Instant instant = Instant.ofEpochMilli(timestamp);
ZoneId zone = ZoneId.systemDefault();
return LocalDateTime.ofInstant(instant, zone);
}
private NormProductionStatistics preciprice2NormProductionStatistics(Preciprice preciprice) {
NormProductionStatistics rts = new NormProductionStatistics();
rts.setPosition(preciprice.getPosition());
rts.setUserName(preciprice.getUserName());
rts.setUserId(preciprice.getUserId() + "");
rts.setSex(preciprice.getSex() == 1 ? "男" : "女");
rts.setAccount(preciprice.getAccount());
rts.setCoefficient(preciprice.getCoefficient().doubleValue());
rts.setGroupId(preciprice.getGroupId());
rts.setGroupName(preciprice.getPosition());
return rts;
}
private <M, T> IPage<T> copyPage(IPage<M> page, List<T> target) {
IPage<T> rts = new Page<>();
rts.setCurrent(page.getCurrent());
rts.setRecords(target);
rts.setSize(page.getSize());
rts.setPages(page.getPages());
rts.setTotal(page.getTotal());
return rts;
}
private void addCount(LocalDateTime date, Map<String, Integer> map) {
Date nextDate = DateUtil.endOfMonth(asDate(date));
map.put(nextDate.getMonth() + 1 + "", map.get(nextDate.getMonth() + 1 + "") + 1);
}
private void addCount(LocalDate date, Map<String, Integer> map) {
Date nextDate = DateUtil.endOfMonth(asDate(date));
map.put(nextDate.getMonth() + 1 + "", map.get(nextDate.getMonth() + 1 + "") + 1);
}
private static Date asDate(LocalDate localDate) {
return Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
}
private static Date asDate(LocalDateTime localDateTime) {
return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
}
private Map<String, Integer> initMonthMoneyMap(long start, long end) {
Map<String, Integer> map = new LinkedHashMap();
for (long i = start; i <= end; i = DateUtil.offsetMonth(DateUtil.date(i), 1).getTime()) {
map.put(DateUtil.endOfMonth(DateUtil.date(i)).getMonth() + 1 + "", 0);
}
return map;
}
private static long getDefaultStart(long start) {
//如果没传时间进来 默认开始时间是今天开始时间
if (start == 0) {
start = System.currentTimeMillis();
start = DateUtil.beginOfYear(DateUtil.date(start)).getTime();
}
return start;
}
private static long getDefaultEnd(long end) {
//如果没传时间进来 默认开始时间是今天开始时间
if (end == 0) {
end = System.currentTimeMillis();
end = DateUtil.endOfYear(DateUtil.date(end)).getTime();
}
return end;
}
/**
* 计算标准产值的工时标准系数 plan
* 额定工日*建议系数/报出对应分析结果*考核工值*分析占比
......@@ -718,14 +510,15 @@ public class PrecipriceServiceImpl extends ServiceImpl<PrecipriceMapper, Precipr
private BigDecimal calculateWorkTimeCoefficient(NormProduction normProduction, Double rate) {
//计算出工时标准系数:
//额定工日*建议系数/报出对应分析结果*考核工值*分析占比
BigDecimal quotaDayBig = BigDecimal.valueOf(normProduction.getQuotaDay());
BigDecimal coefficientBig = BigDecimal.valueOf(normProduction.getCoefficient());
BigDecimal reportedAnalyseRtsBig = BigDecimal.valueOf(normProduction.getReportedAnalyseResult());
BigDecimal assessValueBig = BigDecimal.valueOf(normProduction.getAssessValue());
BigDecimal analyseRateBig = BigDecimal.valueOf(rate);
BigDecimal quotaDayBig = BigDecimal.valueOf(normProduction.getQuotaDay()); //定额工日
BigDecimal coefficientBig = BigDecimal.valueOf(normProduction.getCoefficient()); //建议系数
BigDecimal reportedAnalyseRtsBig = BigDecimal.valueOf(normProduction.getReportedAnalyseResult()); //报出分析结果
BigDecimal assessValueBig = BigDecimal.valueOf(normProduction.getAssessValue()); //考核工值
BigDecimal analyseRateBig = BigDecimal.valueOf(rate); //分析占比
return quotaDayBig.multiply(coefficientBig)
.divide(reportedAnalyseRtsBig, 6, RoundingMode.HALF_DOWN)
.divide(reportedAnalyseRtsBig, 2, RoundingMode.HALF_DOWN)
.multiply(assessValueBig).multiply(analyseRateBig)
.setScale(6, RoundingMode.HALF_DOWN);
.setScale(2, RoundingMode.HALF_DOWN);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment