package com.ruoyi.inspect.amqp;
|
|
import cn.hutool.core.date.DateTime;
|
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
import com.alibaba.fastjson.JSONArray;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.rabbitmq.client.Channel;
|
|
import com.ruoyi.basic.mapper.StandardProductListMapper;
|
import com.ruoyi.basic.vo.StandardProductVO;
|
import com.ruoyi.common.utils.JackSonUtil;
|
import com.ruoyi.inspect.amqp.constants.ExchangeConstants;
|
import com.ruoyi.inspect.amqp.constants.QueueConstants;
|
import com.ruoyi.inspect.amqp.constants.RouterKeyConstants;
|
import com.ruoyi.inspect.dto.WorkTimeDTO;
|
import com.ruoyi.inspect.mapper.InsProductMapper;
|
import com.ruoyi.inspect.mapper.InsProductResultMapper;
|
import com.ruoyi.inspect.mapper.InsSampleUserMapper;
|
import com.ruoyi.inspect.pojo.*;
|
import com.ruoyi.performance.mapper.AuxiliaryOutputWorkingHoursMapper;
|
import com.ruoyi.performance.mapper.PerformanceShiftMapper;
|
import com.ruoyi.performance.mapper.ShiftTimeMapper;
|
import com.ruoyi.performance.pojo.AuxiliaryOutputWorkingHours;
|
import com.ruoyi.performance.pojo.PerformanceShift;
|
import com.ruoyi.performance.pojo.ShiftTime;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.StringUtils;
|
import org.apache.logging.log4j.util.Strings;
|
import org.springframework.amqp.core.Message;
|
import org.springframework.amqp.rabbit.annotation.Exchange;
|
import org.springframework.amqp.rabbit.annotation.Queue;
|
import org.springframework.amqp.rabbit.annotation.QueueBinding;
|
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.stereotype.Component;
|
import org.springframework.transaction.annotation.Isolation;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.annotation.Resource;
|
import java.io.IOException;
|
import java.math.BigDecimal;
|
import java.math.RoundingMode;
|
import java.text.SimpleDateFormat;
|
import java.time.LocalDate;
|
import java.time.LocalDateTime;
|
import java.time.LocalTime;
|
import java.time.format.DateTimeFormatter;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
@Slf4j
|
@Component
|
public class WorkTimeInsertConsumer {
|
|
@Resource
|
private StandardProductListMapper standardProductListMapper;
|
|
@Resource
|
private InsSampleUserMapper insSampleUserMapper;
|
|
@Resource
|
private InsProductMapper insProductMapper;
|
|
@Resource
|
private ShiftTimeMapper shiftTimeMapper;
|
|
@Resource
|
private PerformanceShiftMapper performanceShiftMapper;
|
|
@Resource
|
private InsProductResultMapper insProductResultMapper;
|
|
@Resource
|
AuxiliaryOutputWorkingHoursMapper auxiliaryOutputWorkingHoursMapper;
|
|
/**
|
* 工时计算消费者-光纤试验室
|
* @param jsonStr
|
* @param channel
|
* @param message
|
*/
|
@Transactional(rollbackFor = Exception.class,isolation = Isolation.READ_COMMITTED)
|
@RabbitListener(bindings = @QueueBinding(key = {RouterKeyConstants.GX_KEY},value = @Queue(QueueConstants.GX_QUEUE),exchange = @Exchange(name = ExchangeConstants.WORK_TIME_EXCHANGE)))
|
public void addWorkTimeListenerByGX(String jsonStr, Channel channel, Message message){
|
long deliveryTag = message.getMessageProperties().getDeliveryTag();
|
WorkTimeDTO workTimeDTO = new WorkTimeDTO();
|
try {
|
workTimeDTO = JackSonUtil.unmarshal(jsonStr,WorkTimeDTO.class);
|
addWorkTimeRecord(
|
workTimeDTO.getUserId(),
|
workTimeDTO.getInsOrder(),
|
workTimeDTO.getInsSample(),
|
workTimeDTO.getInsProduct(),
|
workTimeDTO.getParentInsProduct(),
|
workTimeDTO.getCurrentSampleId(),
|
workTimeDTO.getInsProductId(),
|
workTimeDTO.getOldResults(),
|
workTimeDTO.getNewResult()
|
);
|
//执行成功,手动确认
|
channel.basicAck(deliveryTag,false);
|
log.info("光纤试验室工时计算队列:执行成功:用户id:{},检验项id:{}",workTimeDTO.getUserId(),workTimeDTO.getInsProductId());
|
} catch (Exception e) {
|
log.error("光纤试验室工时计算队列:执行失败:用户id:{},检验项id:{}",workTimeDTO.getUserId(),workTimeDTO.getInsProductId(),e);
|
try {
|
channel.basicNack(deliveryTag,false,false);
|
} catch (IOException ex) {
|
throw new RuntimeException(ex);
|
}
|
throw new RuntimeException(e);
|
}
|
}
|
/**
|
* 工时计算消费者-材料试验室
|
* @param jsonStr
|
* @param channel
|
* @param message
|
*/
|
@Transactional(rollbackFor = Exception.class,isolation = Isolation.READ_COMMITTED)
|
@RabbitListener(bindings = @QueueBinding(key = {RouterKeyConstants.CL_KEY},value = @Queue(QueueConstants.CL_QUEUE),exchange = @Exchange(name = ExchangeConstants.WORK_TIME_EXCHANGE)))
|
public void addWorkTimeListenerByCL(String jsonStr, Channel channel, Message message){
|
long deliveryTag = message.getMessageProperties().getDeliveryTag();
|
WorkTimeDTO workTimeDTO = new WorkTimeDTO();
|
try {
|
workTimeDTO = JackSonUtil.unmarshal(jsonStr,WorkTimeDTO.class);
|
addWorkTimeRecord(
|
workTimeDTO.getUserId(),
|
workTimeDTO.getInsOrder(),
|
workTimeDTO.getInsSample(),
|
workTimeDTO.getInsProduct(),
|
workTimeDTO.getParentInsProduct(),
|
workTimeDTO.getCurrentSampleId(),
|
workTimeDTO.getInsProductId(),
|
workTimeDTO.getOldResults(),
|
workTimeDTO.getNewResult()
|
);
|
//执行成功,手动确认
|
channel.basicAck(deliveryTag,false);
|
log.info("材料试验室工时计算队列:执行成功:用户id:{},检验项id:{}",workTimeDTO.getUserId(),workTimeDTO.getInsProductId());
|
} catch (Exception e) {
|
log.error("材料试验室工时计算队列:执行失败:用户id:{},检验项id:{}",workTimeDTO.getUserId(),workTimeDTO.getInsProductId(),e);
|
try {
|
channel.basicNack(deliveryTag,false,false);
|
} catch (IOException ex) {
|
throw new RuntimeException(ex);
|
}
|
throw new RuntimeException(e);
|
}
|
}
|
/**
|
* 工时计算消费者-机械性能试验室
|
* @param jsonStr
|
* @param channel
|
* @param message
|
*/
|
@Transactional(rollbackFor = Exception.class,isolation = Isolation.READ_COMMITTED)
|
@RabbitListener(bindings = @QueueBinding(key = {RouterKeyConstants.JX_KEY},value = @Queue(QueueConstants.JX_QUEUE),exchange = @Exchange(name = ExchangeConstants.WORK_TIME_EXCHANGE)))
|
public void addWorkTimeListenerByJX(String jsonStr, Channel channel, Message message){
|
long deliveryTag = message.getMessageProperties().getDeliveryTag();
|
WorkTimeDTO workTimeDTO = new WorkTimeDTO();
|
try {
|
workTimeDTO = JackSonUtil.unmarshal(jsonStr,WorkTimeDTO.class);
|
addWorkTimeRecord(
|
workTimeDTO.getUserId(),
|
workTimeDTO.getInsOrder(),
|
workTimeDTO.getInsSample(),
|
workTimeDTO.getInsProduct(),
|
workTimeDTO.getParentInsProduct(),
|
workTimeDTO.getCurrentSampleId(),
|
workTimeDTO.getInsProductId(),
|
workTimeDTO.getOldResults(),
|
workTimeDTO.getNewResult()
|
);
|
//执行成功,手动确认
|
channel.basicAck(deliveryTag,false);
|
log.info("机械性能试验室工时计算队列:执行成功:用户id:{},检验项id:{}",workTimeDTO.getUserId(),workTimeDTO.getInsProductId());
|
} catch (Exception e) {
|
log.error("机械性能试验室工时计算队列:执行失败:用户id:{},检验项id:{}",workTimeDTO.getUserId(),workTimeDTO.getInsProductId(),e);
|
try {
|
channel.basicNack(deliveryTag,false,false);
|
} catch (IOException ex) {
|
throw new RuntimeException(ex);
|
}
|
throw new RuntimeException(e);
|
}
|
}
|
/**
|
* 工时计算消费者-电力试验室
|
* @param jsonStr
|
* @param channel
|
* @param message
|
*/
|
@Transactional(rollbackFor = Exception.class,isolation = Isolation.READ_COMMITTED)
|
@RabbitListener(bindings = @QueueBinding(key = {RouterKeyConstants.DL_KEY},value = @Queue(QueueConstants.DL_QUEUE),exchange = @Exchange(name = ExchangeConstants.WORK_TIME_EXCHANGE)))
|
public void addWorkTimeListenerByDL(String jsonStr, Channel channel, Message message){
|
long deliveryTag = message.getMessageProperties().getDeliveryTag();
|
WorkTimeDTO workTimeDTO = new WorkTimeDTO();
|
try {
|
workTimeDTO = JackSonUtil.unmarshal(jsonStr,WorkTimeDTO.class);
|
addWorkTimeRecord(
|
workTimeDTO.getUserId(),
|
workTimeDTO.getInsOrder(),
|
workTimeDTO.getInsSample(),
|
workTimeDTO.getInsProduct(),
|
workTimeDTO.getParentInsProduct(),
|
workTimeDTO.getCurrentSampleId(),
|
workTimeDTO.getInsProductId(),
|
workTimeDTO.getOldResults(),
|
workTimeDTO.getNewResult()
|
);
|
//执行成功,手动确认
|
channel.basicAck(deliveryTag,false);
|
log.info("电力试验室工时计算队列:执行成功:用户id:{},检验项id:{}",workTimeDTO.getUserId(),workTimeDTO.getInsProductId());
|
} catch (Exception e) {
|
log.error("电力试验室工时计算队列:执行失败:用户id:{},检验项id:{}",workTimeDTO.getUserId(),workTimeDTO.getInsProductId(),e);
|
try {
|
channel.basicNack(deliveryTag,false,false);
|
} catch (IOException ex) {
|
throw new RuntimeException(ex);
|
}
|
throw new RuntimeException(e);
|
}
|
}
|
|
|
/**
|
* 添加工时记录
|
* @param userId 当前登录人id
|
* @param insOrder 订单主体
|
* @param insSample 样品信息
|
* @param insProduct 检验项信息
|
* @param parentInsProduct 父检验项信息
|
* @param currentSampleId 当前样品id
|
* @param k 循环key,当前检验项id
|
* @param oldResults 旧的检验结果列表
|
* @param newResult 新的检验结果
|
*/
|
public synchronized void addWorkTimeRecord(Integer userId,
|
InsOrder insOrder,
|
InsSample insSample,
|
InsProduct insProduct,
|
InsProduct parentInsProduct,
|
Integer currentSampleId,
|
String k,
|
List<InsProductResult> oldResults,
|
InsProductResult newResult){
|
//校验如果这个人这个检测项目已经添加过了则不需要再新增
|
//首先判断当前人的当前时间是否是排班时间内,如果不是就是加班
|
LocalDateTime today = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT);
|
PerformanceShift performanceShift = performanceShiftMapper.selectOne(Wrappers.<PerformanceShift>lambdaQuery()
|
.eq(PerformanceShift::getUserId, userId)
|
.eq(PerformanceShift::getWorkTime, today));
|
if (ObjectUtils.isNotEmpty(performanceShift)) {
|
ShiftTime shiftTime = shiftTimeMapper.selectOne(Wrappers.<ShiftTime>lambdaQuery().eq(ShiftTime::getShift, performanceShift.getShift()));
|
// 半天的情况 7:30 23:30
|
if(performanceShift.getShift().equals("5")) {
|
shiftTime = new ShiftTime();
|
shiftTime.setStartTime("07:30");
|
shiftTime.setEndTime("23:30");
|
}
|
// 检查当前时间是否在范围内(包括边界)
|
boolean isWithinRange;
|
boolean isCross; // 是否将当前检验单子的工时计算到班次开始天
|
DateTimeFormatter forma = DateTimeFormatter.ofPattern("HH:mm");
|
LocalTime now = LocalTime.now();
|
|
//shiftTime为空,表示未配置时间
|
if(Objects.isNull(shiftTime)){
|
isCross = true;
|
isWithinRange=false;
|
}else{
|
LocalTime startTime = LocalTime.parse(shiftTime.getStartTime(), forma);
|
LocalTime endTime = LocalTime.parse(shiftTime.getEndTime(), forma);
|
|
// 如果当前时间不在今天的班次内 17:00~5.00 15.00 首先判断是否跨天了
|
// 跨天的情况
|
if (startTime.isAfter(endTime)) {
|
// 查看当前时间是否在班次时间内
|
if (now.isAfter(startTime)) {
|
// 如果是在结束时间之后那么就是正常上班
|
isWithinRange = true;
|
isCross = false;
|
} else {
|
// 当前时间不在班次内,查看昨天的班次
|
LocalDateTime yesterday = LocalDateTime.of(LocalDate.now().minusDays(1), LocalTime.MIDNIGHT);
|
PerformanceShift yesterdayShift = performanceShiftMapper.selectOne(Wrappers.<PerformanceShift>lambdaQuery()
|
.eq(PerformanceShift::getUserId, userId)
|
.eq(PerformanceShift::getWorkTime, yesterday));
|
ShiftTime yesterdayShiftTime = shiftTimeMapper.selectOne(Wrappers.<ShiftTime>lambdaQuery().eq(ShiftTime::getShift, yesterdayShift.getShift()));
|
// 如果昨天的班次不为空,那么就要看昨天的班次时间
|
if (!Objects.isNull(yesterdayShiftTime)) {
|
LocalTime yesterdayStartTime = LocalTime.parse(yesterdayShiftTime.getStartTime(), forma);
|
LocalTime yesterdayEndTime = LocalTime.parse(yesterdayShiftTime.getEndTime(), forma);
|
// 昨天的班次是否跨天
|
if (yesterdayStartTime.isAfter(yesterdayEndTime)) {
|
// 如果昨天的班次跨天了,那么就要看今天是否在昨天的班次内,并且只能是在结束时间之前,已经实现了跨天
|
if (now.isBefore(yesterdayEndTime)) {
|
// 在昨天班次时间内正常上班,工时计算到昨天
|
isWithinRange = true;
|
isCross = true;
|
} else {
|
// 不在昨天班次时间内就是加班,工时计算到昨天
|
isWithinRange = false;
|
isCross = true;
|
}
|
} else {
|
// 昨天的班次没有跨天 如果当前时间在今天班次开始时间之前就是昨天的加班,否则就是今天的加班
|
if (now.isBefore(startTime)) {
|
isWithinRange = false;
|
isCross = true;
|
} else {
|
isWithinRange = false;
|
isCross = false;
|
}
|
}
|
} else {
|
isWithinRange = false;
|
// 如果是在开始时间之前那么就要算到昨天
|
if (now.isBefore(startTime)) {
|
isCross = true;
|
} else {
|
isCross = false;
|
}
|
}
|
}
|
} else {
|
// 当前班次不跨天的情况下
|
// 如果当前时间在开始时间之前,查昨天的班次看当前时间是否在昨天的班次内
|
if (now.isBefore(startTime)) {
|
// 查看昨天是否跨天
|
LocalDateTime yesterday = LocalDateTime.of(LocalDate.now().minusDays(1), LocalTime.MIDNIGHT);
|
PerformanceShift yesterdayShift = performanceShiftMapper.selectOne(Wrappers.<PerformanceShift>lambdaQuery()
|
.eq(PerformanceShift::getUserId, userId)
|
.eq(PerformanceShift::getWorkTime, yesterday));
|
ShiftTime yesterdayShiftTime = shiftTimeMapper.selectOne(Wrappers.<ShiftTime>lambdaQuery().eq(ShiftTime::getShift, yesterdayShift.getShift()));
|
LocalTime yesterdayStartTime = LocalTime.parse(yesterdayShiftTime.getStartTime(), forma);
|
LocalTime yesterdayEndTime = LocalTime.parse(yesterdayShiftTime.getEndTime(), forma);
|
if (yesterdayStartTime.isAfter(yesterdayEndTime)) {
|
// 如果昨天跨天
|
if (now.isBefore(yesterdayEndTime)) {
|
// 在昨天的班次时间内正常上班,工时计算到昨天
|
isWithinRange = true;
|
isCross = true;
|
} else {
|
// 不在昨天班次时间内就是加班,工时计算到昨天
|
isWithinRange = false;
|
isCross = true;
|
}
|
} else {
|
// 昨天不跨天
|
isWithinRange = false;
|
isCross = true;
|
}
|
} else if (now.isAfter(endTime)) {
|
// 如果当前时间在结束时间之后,那么就是今天的加班
|
isWithinRange = false;
|
isCross = false;
|
} else {
|
// 正常上班
|
isWithinRange = true;
|
isCross = false;
|
}
|
}
|
}
|
//检验父项名称
|
String inspectItem = ObjectUtil.isNotNull(parentInsProduct) ? parentInsProduct.getInspectionItem() : insProduct.getInspectionItem();
|
//检验子项名称
|
String inspectSubItem = ObjectUtil.isNotNull(parentInsProduct) ? parentInsProduct.getInspectionItemSubclass() : insProduct.getInspectionItemSubclass();
|
//加班
|
List<AuxiliaryOutputWorkingHours> count1s = auxiliaryOutputWorkingHoursMapper.selectList(Wrappers.<AuxiliaryOutputWorkingHours>lambdaQuery()
|
.eq(AuxiliaryOutputWorkingHours::getCheckId, userId)
|
.eq(AuxiliaryOutputWorkingHours::getInspectionItem, inspectItem)
|
.eq(AuxiliaryOutputWorkingHours::getInspectionItemSubclass, inspectSubItem)
|
.eq(AuxiliaryOutputWorkingHours::getOvertimeOrderNo, insOrder.getEntrustCode())
|
.eq(AuxiliaryOutputWorkingHours::getSample, insSample.getSampleCode()));
|
if (count1s.size() > 1) {
|
for (int i = 1; i < count1s.size(); i++) {
|
// 特殊项目不能删除
|
List<String> arrList = Arrays.asList("温度循环", "热循环", "温升试验", "单根垂直燃烧", "消振评估");
|
if (arrList.contains(count1s.get(i).getInspectionItem()) ||
|
count1s.get(i).getInspectionItem().contains("松套管") ||
|
count1s.get(i).getInspectionItemSubclass().contains("松套管") ||
|
!Objects.isNull(insProduct.getInsFiberId()) ||
|
!Objects.isNull(insProduct.getInsFibersId())) {
|
continue;
|
}
|
// 如果是光纤配置下的光纤接头损耗,那么就删除
|
if((!Objects.isNull(insProduct.getInsFiberId()) ||
|
!Objects.isNull(insProduct.getInsFibersId())) && insProduct.getInspectionItem().equals("光纤接头损耗") ) {
|
auxiliaryOutputWorkingHoursMapper.deleteById(count1s.get(i));
|
}
|
auxiliaryOutputWorkingHoursMapper.deleteById(count1s.get(i));
|
}
|
}
|
//非加班
|
List<AuxiliaryOutputWorkingHours> count2s = auxiliaryOutputWorkingHoursMapper.selectList(Wrappers.<AuxiliaryOutputWorkingHours>lambdaQuery()
|
.eq(AuxiliaryOutputWorkingHours::getCheckId, userId)
|
.eq(AuxiliaryOutputWorkingHours::getInspectionItem, inspectItem)
|
.eq(AuxiliaryOutputWorkingHours::getInspectionItemSubclass, inspectSubItem)
|
.eq(AuxiliaryOutputWorkingHours::getOrderNo, insOrder.getEntrustCode())
|
.eq(AuxiliaryOutputWorkingHours::getSample, insSample.getSampleCode()));
|
if (count2s.size() > 1) {
|
for (int i = 1; i < count2s.size(); i++) {
|
// 特殊项目不能删除
|
List<String> arrList = Arrays.asList("温度循环", "热循环", "温升试验", "单根垂直燃烧", "消振评估");
|
if (arrList.contains(count2s.get(i).getInspectionItem()) ||
|
count2s.get(i).getInspectionItem().contains("松套管") ||
|
count2s.get(i).getInspectionItemSubclass().contains("松套管") ||
|
!Objects.isNull(insProduct.getInsFiberId()) ||
|
!Objects.isNull(insProduct.getInsFibersId())) {
|
continue;
|
}
|
// 如果是光纤配置下的光纤接头损耗,那么就删除
|
if((!Objects.isNull(insProduct.getInsFiberId()) ||
|
!Objects.isNull(insProduct.getInsFibersId())) && insProduct.getInspectionItem().equals("光纤接头损耗")) {
|
auxiliaryOutputWorkingHoursMapper.deleteById(count2s.get(i));
|
}
|
auxiliaryOutputWorkingHoursMapper.deleteById(count2s.get(i));
|
}
|
}
|
//产量工时计算
|
AuxiliaryOutputWorkingHours auxiliaryOutputWorkingHours = new AuxiliaryOutputWorkingHours();
|
//工时
|
BigDecimal manHour = BigDecimal.ZERO;
|
// Double manHour = 0.0;
|
StandardProductVO workHourMap = getInspectWorkHourAndGroup(Objects.isNull(parentInsProduct) ? insProduct : parentInsProduct);
|
if (ObjectUtil.isNotNull(workHourMap)) {
|
manHour = new BigDecimal(workHourMap.getManHour());
|
}
|
if (isWithinRange) {
|
//在时间内就是正常上班
|
auxiliaryOutputWorkingHours.setOrderNo(insOrder.getEntrustCode());//非加班委托单号
|
auxiliaryOutputWorkingHours.setWorkTime(manHour.doubleValue());//非加班工时
|
auxiliaryOutputWorkingHours.setAmount(1);//非加班数量
|
} else {
|
//加班
|
auxiliaryOutputWorkingHours.setOvertimeOrderNo(insOrder.getEntrustCode());//加班委托单号
|
auxiliaryOutputWorkingHours.setOvertimeWorkTime(manHour.doubleValue());//加班工时
|
auxiliaryOutputWorkingHours.setOvertimeAmount(1);//加班数量
|
}
|
|
//新增工时
|
if (CollectionUtils.isEmpty(count2s) && CollectionUtils.isEmpty(count1s)) {
|
//日期格式
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
DateTimeFormatter formatters = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
//当前时间
|
LocalDateTime localDateTime = LocalDateTime.now();
|
DateTime parse = DateUtil.parse(localDateTime.format(formatter));
|
//提出公共字段
|
auxiliaryOutputWorkingHours.setInspectionItem(inspectItem);//检测父项
|
auxiliaryOutputWorkingHours.setInspectionItemSubclass(inspectSubItem);//检测子项
|
auxiliaryOutputWorkingHours.setSample(insSample.getSampleCode());//样品编号
|
auxiliaryOutputWorkingHours.setOutputWorkTime((ObjectUtils.isNotEmpty(auxiliaryOutputWorkingHours.getOvertimeWorkTime()) ? auxiliaryOutputWorkingHours.getOvertimeWorkTime() : 0) + (ObjectUtils.isNotEmpty(auxiliaryOutputWorkingHours.getWorkTime()) ? auxiliaryOutputWorkingHours.getWorkTime() : 0));//产量工时
|
auxiliaryOutputWorkingHours.setManHourGroup(workHourMap.getManHourGroup());//工时分组
|
if (isCross) {
|
List<Integer> list = Arrays.asList(3, 4, 6); // 休息 请假 出差
|
List<PerformanceShift> performanceShifts = performanceShiftMapper.selectList(new LambdaQueryWrapper<PerformanceShift>()
|
.eq(PerformanceShift::getUserId, userId)
|
.lt(PerformanceShift::getWorkTime, localDateTime.toLocalDate().atStartOfDay().format(formatters))
|
.notIn(PerformanceShift::getShift, list)
|
.orderByDesc(PerformanceShift::getWorkTime));
|
auxiliaryOutputWorkingHours.setDateTime(performanceShifts.get(0).getWorkTime().format(formatters));//日期 前一天
|
|
} else {
|
auxiliaryOutputWorkingHours.setDateTime(LocalDateTime.now().toLocalDate().atStartOfDay().format(formatters));//日期 当前天
|
}
|
auxiliaryOutputWorkingHours.setWeekDay(getWeek(localDateTime.format(formatters)));//星期
|
auxiliaryOutputWorkingHours.setWeek(String.valueOf(DateUtil.weekOfYear(DateUtil.offsetDay(parse, 1))));//周次
|
auxiliaryOutputWorkingHours.setCheckId(userId);//检测人
|
try {
|
|
if (CollectionUtils.isEmpty(oldResults) && !newResult.getInsValue().equals("[]") ||
|
(CollectionUtils.isNotEmpty(oldResults) && !oldResults.get(0).getInsValue().equals(newResult.getInsValue())/* && !oldResults.get(0).getInsValue().equals("[]")*/) ||
|
(newResult.getInsValue().equals("[]") && !newResult.getComValue().equals("[]"))) {
|
List<String> insItems = Arrays.asList("握力", "拉断力", "破断");
|
if (StringUtils.equals("电力产品实验室", insProduct.getLaboratory()) && insItems.contains(insProduct.getInspectionItem())) {
|
//电力产品实验室的握力和拉断力项目,参与检验的人员都要加工时
|
//查询参与检验的人员
|
List<InsSampleUser> insSampleUsers = insSampleUserMapper.selectList(Wrappers.<InsSampleUser>lambdaQuery().eq(InsSampleUser::getInsSampleId, insOrder.getId()));
|
insSampleUsers.forEach(user -> {
|
auxiliaryOutputWorkingHours.setCheckId(user.getUserId());//检测人
|
auxiliaryOutputWorkingHoursMapper.insert(auxiliaryOutputWorkingHours);
|
auxiliaryOutputWorkingHours.setId(null);
|
});
|
|
} else {
|
if (insProduct.getInspectionItem().contains("弧垂")) {
|
// 样品下的检验项包含弧垂的个数
|
AuxiliaryOutputWorkingHours sampleCount = auxiliaryOutputWorkingHoursMapper.selectOne(new LambdaQueryWrapper<AuxiliaryOutputWorkingHours>()
|
.eq(AuxiliaryOutputWorkingHours::getSample, insSample.getSampleCode()) // 样品编号
|
.eq(AuxiliaryOutputWorkingHours::getInspectionItem, parentInsProduct.getInspectionItem()) // 检验项目
|
.and(item -> item.eq(AuxiliaryOutputWorkingHours::getOrderNo, insOrder.getEntrustCode()) // 非加班委托单号
|
.or()
|
.eq(AuxiliaryOutputWorkingHours::getOvertimeOrderNo, insOrder.getEntrustCode())) // 加班委托单号
|
);
|
auxiliaryOutputWorkingHours.setInspectionItem(parentInsProduct.getInspectionItem());
|
if (Objects.isNull(sampleCount)) {
|
auxiliaryOutputWorkingHoursMapper.insert(auxiliaryOutputWorkingHours);
|
}
|
} else {
|
auxiliaryOutputWorkingHoursMapper.insert(auxiliaryOutputWorkingHours);
|
}
|
}
|
} else if (inspectItem.equals("应力应变") && inspectSubItem.equals("弹性模量")) {
|
auxiliaryOutputWorkingHoursMapper.insert(auxiliaryOutputWorkingHours);
|
}
|
} catch (Exception e) {
|
log.error("工时新增失败-->",e);
|
}
|
} else {
|
// 查询当前检验项的工时添加记录
|
List<AuxiliaryOutputWorkingHours> oldRecords = auxiliaryOutputWorkingHoursMapper.selectList(Wrappers.<AuxiliaryOutputWorkingHours>lambdaQuery()
|
.eq(AuxiliaryOutputWorkingHours::getCheckId, userId)
|
.eq(AuxiliaryOutputWorkingHours::getInspectionItem, inspectItem)
|
.eq(AuxiliaryOutputWorkingHours::getInspectionItemSubclass, inspectSubItem)
|
.eq(AuxiliaryOutputWorkingHours::getSample, insSample.getSampleCode())
|
.and(i -> i.eq(AuxiliaryOutputWorkingHours::getOrderNo, insOrder.getEntrustCode())
|
.or()
|
.eq(AuxiliaryOutputWorkingHours::getOvertimeOrderNo, insOrder.getEntrustCode()))
|
.orderByAsc(AuxiliaryOutputWorkingHours::getDateTime)
|
);
|
List<String> special = Arrays.asList("温度循环", "热循环", "温升试验", "单根垂直燃烧", "消振评估");
|
if (special.contains(inspectItem) || inspectItem.contains("松套管") || inspectSubItem.contains("松套管") ||
|
!Objects.isNull(insProduct.getInsFiberId()) ||
|
!Objects.isNull(insProduct.getInsFibersId())) {
|
// 是否需要跨天
|
if (isCross) {
|
DateTimeFormatter formatters = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
List<Integer> list = Arrays.asList(3, 4, 6); // 休息 请假 出差
|
List<PerformanceShift> performanceShifts = performanceShiftMapper.selectList(new LambdaQueryWrapper<PerformanceShift>()
|
.eq(PerformanceShift::getUserId, userId)
|
.lt(PerformanceShift::getWorkTime, LocalDateTime.now().toLocalDate().atStartOfDay().format(formatters))
|
.notIn(PerformanceShift::getShift, list)
|
.orderByDesc(PerformanceShift::getWorkTime));
|
String date = performanceShifts.get(0).getWorkTime().format(formatters); // 前面正常上班的日期
|
boolean addOrUpdate;
|
// 过滤出日期一致的记录
|
List<AuxiliaryOutputWorkingHours> collect2 = oldRecords.stream().filter(item -> item.getDateTime().equals(date)).collect(Collectors.toList());
|
AuxiliaryOutputWorkingHours currentRecord = null;
|
if (CollectionUtils.isNotEmpty(collect2)) {
|
// 有就更新 没有就新增
|
addOrUpdate = true;
|
currentRecord = collect2.get(collect2.size() - 1);
|
} else {
|
addOrUpdate = false;
|
// 新增的日期是有做处理的,所以这里取oldRecords的最后一个
|
currentRecord = oldRecords.get(oldRecords.size() - 1);
|
}
|
specialWorkCount(currentRecord, date, isWithinRange, manHour, currentSampleId, parentInsProduct, auxiliaryOutputWorkingHours, formatters, oldRecords, k, addOrUpdate, insProduct,userId);
|
} else {
|
// 不需要跨天
|
//判断查询得到日期是否要与添加数据的日期一致,如果日期一致,则进行更新,否则新增
|
DateTimeFormatter formatters = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
String date = LocalDateTime.now().toLocalDate().atStartOfDay().format(formatters);
|
boolean addOrUpdate;
|
// 过滤出日期一致的记录
|
List<AuxiliaryOutputWorkingHours> collect2 = oldRecords.stream().filter(item -> item.getDateTime().equals(date)).collect(Collectors.toList());
|
AuxiliaryOutputWorkingHours oldRecord = null;
|
if (CollectionUtils.isNotEmpty(collect2)) {
|
// 有就更新 没有就新增
|
addOrUpdate = true;
|
oldRecord = collect2.get(collect2.size() - 1);
|
} else {
|
addOrUpdate = false;
|
// 新增的日期是有做处理的,所以这里取oldRecords的最后一个
|
oldRecord = oldRecords.get(oldRecords.size() - 1);
|
}
|
// 特殊项工时计算
|
specialWorkCount(oldRecord, date, isWithinRange, manHour, currentSampleId, parentInsProduct, auxiliaryOutputWorkingHours, formatters, oldRecords, k, addOrUpdate, insProduct,userId);
|
}
|
}
|
}
|
}
|
log.info("工时计算完成,productId:{}",k);
|
}
|
|
|
|
/**
|
* 特殊项工时计算
|
*/
|
public synchronized void specialWorkCount(AuxiliaryOutputWorkingHours oldRecord,String date,boolean isWithinRange,
|
BigDecimal manHour,Integer currentSampleId,InsProduct parentInsProduct,
|
AuxiliaryOutputWorkingHours auxiliaryOutputWorkingHours,
|
DateTimeFormatter formatters,
|
List<AuxiliaryOutputWorkingHours> oldRecords,
|
String k,boolean addOrUpdate,
|
InsProduct insProduct,Integer userId) {
|
//判断得到日期是否已经含有数据 有就更新 没有就新增
|
if(addOrUpdate){
|
//更新工时 是否加班
|
List<InsProduct> insProducts = insProductMapper.selectList(new LambdaQueryWrapper<InsProduct>()
|
.eq(InsProduct::getInsSampleId, currentSampleId));
|
String inspectionItem = oldRecord.getInspectionItem();
|
String inspectionItemSubclass = oldRecord.getInspectionItemSubclass();
|
switch (inspectionItem) {
|
case "单根垂直燃烧":
|
//计算工时 查看检验的个数是否与工时的个数一致(区分检验项和检验子项目)
|
int count1 = 0; // 工时的个数
|
InsProduct insProduct2 = insProductMapper.selectById(Integer.parseInt(k));
|
InsProductResult result = insProductResultMapper.selectList(new LambdaQueryWrapper<InsProductResult>()
|
.eq(InsProductResult::getInsProductId, insProduct2.getId())
|
.orderByAsc(InsProductResult::getId)).get(0);
|
List<Map> maps1 = JSONArray.parseArray(result.getInsValue(), Map.class);
|
for (Map map : maps1) {
|
if (Strings.isNotEmpty(map.get("v").toString())) {
|
count1++;
|
}
|
}
|
Integer oldAmount1 = 0;
|
for(AuxiliaryOutputWorkingHours a : oldRecords) {
|
if(a.getInspectionItem().equals(insProduct2.getInspectionItem()) &&
|
a.getInspectionItemSubclass().equals(insProduct2.getInspectionItemSubclass())){
|
oldAmount1 += (Objects.isNull(a.getAmount()) ? 0 : a.getAmount()) + (Objects.isNull(a.getOvertimeAmount()) ? 0 : a.getOvertimeAmount());
|
}
|
}// 之前的工时个数
|
if(count1 > oldAmount1) {
|
if(isWithinRange) {
|
// 非加班
|
oldRecord.setOrderNo(StringUtils.isNotEmpty(oldRecord.getOrderNo()) ? oldRecord.getOrderNo() : oldRecord.getOvertimeOrderNo()); // 非加班委托单号
|
oldRecord.setWorkTime( addAccuracy((Objects.isNull(oldRecord.getWorkTime()) ? 0 : oldRecord.getWorkTime()),manHour.doubleValue())); // 非加班工时
|
oldRecord.setAmount((Objects.isNull(oldRecord.getAmount()) ? 0 : oldRecord.getAmount()) + 1); // 非加班数量
|
oldRecord.setOutputWorkTime((Objects.isNull(oldRecord.getWorkTime()) ? 0 : oldRecord.getWorkTime()) +
|
(Objects.isNull(oldRecord.getOvertimeWorkTime()) ? 0 : oldRecord.getOvertimeWorkTime())); // 产量工时
|
}else {
|
// 加班
|
oldRecord.setOvertimeOrderNo(StringUtils.isNotEmpty(oldRecord.getOrderNo()) ? oldRecord.getOrderNo() : oldRecord.getOvertimeOrderNo()); // 加班委托单号
|
oldRecord.setOvertimeWorkTime(addAccuracy((Objects.isNull(oldRecord.getOvertimeWorkTime()) ? 0: oldRecord.getOvertimeWorkTime()),manHour.doubleValue() ));// 加班工时
|
oldRecord.setOvertimeAmount((Objects.isNull(oldRecord.getOvertimeAmount()) ? 0 : oldRecord.getOvertimeAmount()) + 1); // 加班数量
|
oldRecord.setOutputWorkTime((Objects.isNull(oldRecord.getWorkTime()) ? 0 : oldRecord.getWorkTime()) +
|
(Objects.isNull(oldRecord.getOvertimeWorkTime()) ? 0 : oldRecord.getOvertimeWorkTime())); // 产量工时
|
}
|
auxiliaryOutputWorkingHoursMapper.updateById(oldRecord);
|
}
|
break;
|
case "温度循环":
|
// 查询所有的检验记录 根据productResult的insValue的个数 与 oldRecord的个数进行比较
|
int all = 0; // 所有的温度循环的个数
|
int allValue = 0; // 所有的温度循环的有值的个数
|
int count = 0; // 当前次数的温度有值的个数
|
int countAll = 0; // 当前次数的温度所有的个数
|
if(CollectionUtils.isNotEmpty(insProducts)) {
|
InsProduct insProduct3 = insProductMapper.selectById(Integer.parseInt(k));
|
// 过滤出当前次数的温度
|
List<InsProduct> collect = insProducts.stream()
|
.filter(item -> item.getInspectionItem().equals(insProduct3.getInspectionItem()) &&
|
item.getInspectionItemSubclass().equals(insProduct3.getInspectionItemSubclass()))
|
.collect(Collectors.toList());
|
countAll = collect.size();
|
all = insProducts.size();
|
if(CollectionUtils.isNotEmpty(collect)) {
|
for(InsProduct insProduct1 : collect) {
|
// 查询insProductResult拿到insValue的有值的个数
|
InsProductResult insProductResult = insProductResultMapper.selectOne(new LambdaQueryWrapper<InsProductResult>()
|
.eq(InsProductResult::getInsProductId, insProduct1.getId()));
|
if(!Objects.isNull(insProductResult)) {
|
// insProductResult不为空,获取有值的个数
|
List<Map> maps = JSONArray.parseArray(insProductResult.getInsValue(), Map.class);
|
for (Map map : maps) {
|
if (Strings.isNotEmpty(map.get("v").toString())) {
|
count++;
|
break;
|
}
|
}
|
}
|
}
|
// 所有 有值的个数
|
for (InsProduct insProduct1 : insProducts) {
|
// 查询insProductResult拿到insValue的有值的个数
|
InsProductResult insProductResult = insProductResultMapper.selectOne(new LambdaQueryWrapper<InsProductResult>()
|
.eq(InsProductResult::getInsProductId, insProduct1.getId()));
|
if(!Objects.isNull(insProductResult)) {
|
// insProductResult不为空,获取有值的个数
|
List<Map> maps = JSONArray.parseArray(insProductResult.getInsValue(), Map.class);
|
for (Map map : maps) {
|
if (Strings.isNotEmpty(map.get("v").toString())) {
|
allValue++;
|
break;
|
}
|
}
|
}
|
}
|
}
|
}
|
Integer oldAmount = 0; // 已经添加的工时个数
|
for(AuxiliaryOutputWorkingHours a : oldRecords) {
|
oldAmount += (Objects.isNull(a.getAmount()) ? 0 : a.getAmount()) + (Objects.isNull(a.getOvertimeAmount()) ? 0 : a.getOvertimeAmount());
|
}
|
if(all > oldAmount && count < countAll && allValue > oldAmount) {
|
if(isWithinRange) {
|
// 非加班工时
|
oldRecord.setOrderNo(StringUtils.isNotEmpty(oldRecord.getOrderNo()) ? oldRecord.getOrderNo() : oldRecord.getOvertimeOrderNo()); // 非加班委托单号
|
oldRecord.setAmount((Objects.isNull(oldRecord.getAmount()) ? 0 : oldRecord.getAmount()) + 1);
|
oldRecord.setWorkTime(addAccuracy((Objects.isNull(oldRecord.getWorkTime()) ? 0 : oldRecord.getWorkTime()),manHour.doubleValue()));
|
oldRecord.setOutputWorkTime((Objects.isNull(oldRecord.getWorkTime()) ? 0 : oldRecord.getWorkTime()) +
|
(Objects.isNull(oldRecord.getOvertimeWorkTime()) ? 0 : oldRecord.getOvertimeWorkTime()));
|
|
}else {
|
// 加班工时
|
oldRecord.setOvertimeOrderNo(StringUtils.isNotEmpty(oldRecord.getOrderNo()) ? oldRecord.getOrderNo() : oldRecord.getOvertimeOrderNo()); // 非加班委托单号
|
oldRecord.setOvertimeAmount((Objects.isNull(oldRecord.getOvertimeAmount()) ? 0 : oldRecord.getOvertimeAmount()) + 1);
|
oldRecord.setOvertimeWorkTime(addAccuracy((Objects.isNull(oldRecord.getOvertimeWorkTime()) ? 0 : oldRecord.getOvertimeWorkTime()),manHour.doubleValue() ));
|
oldRecord.setOutputWorkTime((Objects.isNull(oldRecord.getWorkTime()) ? 0 : oldRecord.getWorkTime()) +
|
(Objects.isNull(oldRecord.getOvertimeWorkTime()) ? 0 : oldRecord.getOvertimeWorkTime()));
|
}
|
auxiliaryOutputWorkingHoursMapper.updateById(oldRecord);
|
}
|
break;
|
case "温升试验":
|
// 按照检验项分组 有几个检验值就算几次工时
|
Map<String, List<InsProduct>> collect = insProductMapper.selectList(new LambdaQueryWrapper<InsProduct>()
|
.eq(InsProduct::getSpecialItemParentId, parentInsProduct.getId()))
|
.stream()
|
.collect(Collectors.groupingBy(InsProduct::getInspectionItem));
|
int group = 0;
|
for (Map.Entry<String,List<InsProduct>> entry : collect.entrySet()) {
|
int minValue = Integer.MIN_VALUE;
|
List<InsProduct> insProducts1 = entry.getValue();
|
for (InsProduct product1 : insProducts1) {
|
InsProductResult insProductResult = insProductResultMapper.selectOne(Wrappers.<InsProductResult>lambdaQuery()
|
.eq(InsProductResult::getInsProductId, product1.getId()));
|
if(!Objects.isNull(insProductResult)) {
|
List<Map> maps = com.alibaba.fastjson2.JSON.parseArray(insProductResult.getInsValue(), Map.class);
|
// 最长的insValue 就有几组工时
|
if(maps.size() > minValue) {
|
minValue = maps.size();
|
}
|
}
|
}
|
if(minValue != Integer.MIN_VALUE) {
|
group += minValue;
|
}
|
}
|
double oldWorkTime2 = 0;
|
double oldAmount2 = 0;
|
for(AuxiliaryOutputWorkingHours a : oldRecords) {
|
oldWorkTime2 += (Objects.isNull(a.getOvertimeWorkTime()) ? 0 : a.getOvertimeWorkTime()) + (Objects.isNull(a.getWorkTime()) ? 0 : a.getWorkTime());
|
oldAmount2+= (Objects.isNull(a.getAmount()) ? 0 : a.getAmount()) + (Objects.isNull(a.getOvertimeAmount()) ? 0 : a.getOvertimeAmount());
|
}
|
// 检验的组数大于已经添加的组数就要更新工时
|
int oldGroup1 = 0;
|
if(manHour.doubleValue() != 0) {
|
oldGroup1 =(int) (oldWorkTime2 / manHour.doubleValue());
|
}
|
if((group > oldGroup1) && (group > oldAmount2)) {
|
if(isWithinRange) {
|
// 非加班
|
oldRecord.setOrderNo(StringUtils.isNotEmpty(oldRecord.getOrderNo()) ? oldRecord.getOrderNo() : oldRecord.getOvertimeOrderNo()); // 非加班委托单号
|
oldRecord.setAmount((Objects.isNull(oldRecord.getAmount()) ? 0 : oldRecord.getAmount()) + 1); // 非加班数量
|
oldRecord.setWorkTime(accuracy(manHour,oldRecord.getAmount())); // 非加班工时
|
oldRecord.setOutputWorkTime((Objects.isNull(oldRecord.getWorkTime()) ? 0 : oldRecord.getWorkTime()) +
|
(Objects.isNull(oldRecord.getOvertimeWorkTime()) ? 0 : oldRecord.getOvertimeWorkTime())); // 产量工时
|
}else {
|
// 加班
|
oldRecord.setOvertimeOrderNo(StringUtils.isNotEmpty(oldRecord.getOrderNo()) ? oldRecord.getOrderNo() : oldRecord.getOvertimeOrderNo()); // 加班委托单号
|
oldRecord.setOvertimeAmount((Objects.isNull(oldRecord.getOvertimeAmount()) ? 0 : oldRecord.getOvertimeAmount()) + 1); // 加班数量
|
oldRecord.setOvertimeWorkTime(accuracy(manHour,oldRecord.getOvertimeAmount())); // 加班工时
|
oldRecord.setOutputWorkTime((Objects.isNull(oldRecord.getWorkTime()) ? 0 : oldRecord.getWorkTime()) +
|
(Objects.isNull(oldRecord.getOvertimeWorkTime()) ? 0 : oldRecord.getOvertimeWorkTime())); // 产量工时
|
}
|
auxiliaryOutputWorkingHoursMapper.updateById(oldRecord);
|
}
|
break;
|
case "热循环":
|
// 按照检验项分组 有几个检验值就算几次工时
|
Map<String, List<InsProduct>> collect1 = new HashMap<>();
|
if(Objects.nonNull(parentInsProduct)){
|
collect1 = insProductMapper.selectList(new LambdaQueryWrapper<InsProduct>()
|
.eq(InsProduct::getSpecialItemParentId, parentInsProduct.getId()))
|
.stream()
|
.collect(Collectors.groupingBy(InsProduct::getInspectionItem));
|
}
|
int group1 = 0;
|
for (Map.Entry<String,List<InsProduct>> entry : collect1.entrySet()) {
|
int minValue = Integer.MIN_VALUE;
|
List<InsProduct> insProducts1 = entry.getValue();
|
for (InsProduct product1 : insProducts1) {
|
InsProductResult insProductResult = insProductResultMapper.selectOne(Wrappers.<InsProductResult>lambdaQuery()
|
.eq(InsProductResult::getInsProductId, product1.getId()));
|
if(!Objects.isNull(insProductResult)) {
|
List<Map> maps = com.alibaba.fastjson2.JSON.parseArray(insProductResult.getInsValue(), Map.class);
|
// 最长的insValue 就有几组工时
|
if(maps.size() > minValue) {
|
minValue = maps.size();
|
}
|
}
|
}
|
if(minValue != Integer.MIN_VALUE) {
|
group1 += minValue;
|
}
|
}
|
double oldWorkTime3 = 0;
|
double oldAmount3 = 0;
|
for(AuxiliaryOutputWorkingHours a : oldRecords) {
|
oldWorkTime3 += (Objects.isNull(a.getOvertimeWorkTime()) ? 0 : a.getOvertimeWorkTime()) + (Objects.isNull(a.getWorkTime()) ? 0 : a.getWorkTime());
|
oldAmount3+= (Objects.isNull(a.getAmount()) ? 0 : a.getAmount()) + (Objects.isNull(a.getOvertimeAmount()) ? 0 : a.getOvertimeAmount());
|
}
|
// 检验的组数大于已经添加的组数就要更新工时
|
int oldGroup = 0;
|
if(manHour.doubleValue() != 0) {
|
oldGroup =(int) (oldWorkTime3 / manHour.doubleValue());
|
}
|
|
if((group1 > oldGroup) && (group1 > oldAmount3)) {
|
if(isWithinRange) {
|
// 非加班
|
oldRecord.setOrderNo(StringUtils.isNotEmpty(oldRecord.getOrderNo()) ? oldRecord.getOrderNo() : oldRecord.getOvertimeOrderNo()); // 非加班委托单号
|
oldRecord.setAmount((Objects.isNull(oldRecord.getAmount()) ? 0 : oldRecord.getAmount()) + 1); // 非加班数量
|
oldRecord.setWorkTime(accuracy(manHour, oldRecord.getAmount())); // 非加班工时
|
oldRecord.setOutputWorkTime((Objects.isNull(oldRecord.getWorkTime()) ? 0 : oldRecord.getWorkTime()) +
|
(Objects.isNull(oldRecord.getOvertimeWorkTime()) ? 0 : oldRecord.getOvertimeWorkTime())); // 产量工时
|
}else {
|
// 加班
|
oldRecord.setOvertimeOrderNo(StringUtils.isNotEmpty(oldRecord.getOrderNo()) ? oldRecord.getOrderNo() : oldRecord.getOvertimeOrderNo()); // 加班委托单号
|
oldRecord.setOvertimeAmount((Objects.isNull(oldRecord.getOvertimeAmount()) ? 0 : oldRecord.getOvertimeAmount()) + 1); // 加班数量
|
oldRecord.setOvertimeWorkTime(accuracy(manHour,oldRecord.getOvertimeAmount())); // 加班工时
|
oldRecord.setOutputWorkTime((Objects.isNull(oldRecord.getWorkTime()) ? 0 : oldRecord.getWorkTime()) +
|
(Objects.isNull(oldRecord.getOvertimeWorkTime()) ? 0 : oldRecord.getOvertimeWorkTime())); // 产量工时
|
}
|
auxiliaryOutputWorkingHoursMapper.updateById(oldRecord);
|
}
|
break;
|
case "消振评估":
|
// 根据坐标来进行工时的添加
|
InsProductResult result1 = insProductResultMapper.selectOne(new LambdaQueryWrapper<InsProductResult>()
|
.eq(InsProductResult::getInsProductId, insProduct.getId()));
|
// 工时的个数
|
int count4 = 0;
|
if(!Objects.isNull(result1)) {
|
List<Map> maps = JSONArray.parseArray(result1.getInsValue(), Map.class);
|
// 根据坐标来进行分组
|
Map<Object, List<Map>> coordinate = maps.stream().collect(Collectors.groupingBy(item -> item.get("r")));
|
Iterator<Map.Entry<Object, List<Map>>> iterator = coordinate.entrySet().iterator();
|
while (iterator.hasNext()) {
|
Map.Entry<Object, List<Map>> entry = iterator.next();
|
List<Map> value = entry.getValue();
|
if(value.size() > count4) {
|
count4 = value.size();
|
}
|
}
|
}
|
Integer oldAmount4 = 0; // 已经添加的工时个数
|
for(AuxiliaryOutputWorkingHours a : oldRecords) {
|
oldAmount4 += (Objects.isNull(a.getAmount()) ? 0 : a.getAmount()) + (Objects.isNull(a.getOvertimeAmount()) ? 0 : a.getOvertimeAmount());
|
}
|
if(count4 > oldAmount4) {
|
if(isWithinRange) {
|
// 非加班工时
|
oldRecord.setOrderNo(StringUtils.isNotEmpty(oldRecord.getOrderNo()) ? oldRecord.getOrderNo() : oldRecord.getOvertimeOrderNo()); // 非加班委托单号
|
oldRecord.setAmount((Objects.isNull(oldRecord.getAmount()) ? 0 : oldRecord.getAmount()) + 1); // 非加班个数
|
oldRecord.setWorkTime(addAccuracy((Objects.isNull(oldRecord.getWorkTime()) ? 0 : oldRecord.getWorkTime()),manHour.doubleValue())); // 非加班工时
|
oldRecord.setOutputWorkTime((Objects.isNull(oldRecord.getWorkTime()) ? 0 : oldRecord.getWorkTime()) +
|
(Objects.isNull(oldRecord.getOvertimeWorkTime()) ? 0 : oldRecord.getOvertimeWorkTime())); // 产出工时
|
|
}else {
|
// 加班工时
|
oldRecord.setOvertimeOrderNo(StringUtils.isNotEmpty(oldRecord.getOrderNo()) ? oldRecord.getOrderNo() : oldRecord.getOvertimeOrderNo()); // 非加班委托单号
|
oldRecord.setOvertimeAmount((Objects.isNull(oldRecord.getOvertimeAmount()) ? 0 : oldRecord.getOvertimeAmount()) + 1); // 非加班个数
|
oldRecord.setOvertimeWorkTime(addAccuracy((Objects.isNull(oldRecord.getOvertimeWorkTime()) ? 0 : oldRecord.getOvertimeWorkTime()),manHour.doubleValue() ));
|
oldRecord.setOutputWorkTime((Objects.isNull(oldRecord.getWorkTime()) ? 0 : oldRecord.getWorkTime()) +
|
(Objects.isNull(oldRecord.getOvertimeWorkTime()) ? 0 : oldRecord.getOvertimeWorkTime())); // 产出工时
|
}
|
auxiliaryOutputWorkingHoursMapper.updateById(oldRecord);
|
}
|
break;
|
|
}
|
|
// 松套管 更新
|
if((inspectionItem.contains("松套管") || inspectionItemSubclass.contains("松套管") ||
|
!Objects.isNull(insProduct.getInsFiberId()) ||
|
!Objects.isNull(insProduct.getInsFibersId())) && Objects.isNull(insProduct.getSpecialItemParentId()) && !insProduct.getInspectionItem().equals("光纤接头损耗")) {
|
InsProduct product = insProductMapper.selectById(Integer.parseInt(k));
|
// 查询样品下面所有的松套管 并且过滤出检验项和检验子项相同的数据
|
List<InsProduct> collect = insProductMapper.selectList(new LambdaQueryWrapper<InsProduct>()
|
.eq(InsProduct::getInsSampleId, currentSampleId)
|
.and(item -> item.like(InsProduct::getInspectionItem, "松套管")
|
.or()
|
.like(InsProduct::getInspectionItemSubclass, "松套管")
|
.or()
|
.isNotNull(InsProduct::getInsFibersId)
|
.or()
|
.isNotNull(InsProduct::getInsFiberId))).stream()
|
.filter(item -> item.getInspectionItem().equals(product.getInspectionItem()) &&
|
item.getInspectionItemSubclass().equals(product.getInspectionItemSubclass()))
|
.collect(Collectors.toList());
|
// 检验总共的个数
|
int count = 0;
|
for (InsProduct insProduct1 : collect) {
|
// 查询result表
|
InsProductResult insProductResult = insProductResultMapper.selectOne(new LambdaQueryWrapper<InsProductResult>()
|
.eq(InsProductResult::getInsProductId, insProduct1.getId()));
|
// 如果有值则进行数量相加
|
if(Objects.isNull(insProductResult)) {
|
continue;
|
}
|
count++;
|
// List<Map> maps = JSONArray.parseArray(insProductResult.getInsValue(), Map.class);
|
// for(Map map : maps) {
|
// if(Strings.isNotEmpty(map.get("v").toString())) {
|
// count++;
|
// }
|
// }
|
}
|
// 工时的个数
|
Integer oldAmount = 0;
|
for(AuxiliaryOutputWorkingHours a : oldRecords) {
|
oldAmount += (Objects.isNull(a.getAmount()) ? 0 : a.getAmount()) + (Objects.isNull(a.getOvertimeAmount()) ? 0 : a.getOvertimeAmount());
|
}
|
if((count > oldAmount)) {
|
if(isWithinRange) {
|
// 非加班
|
oldRecord.setOrderNo(StringUtils.isNotEmpty(oldRecord.getOrderNo()) ? oldRecord.getOrderNo() : oldRecord.getOvertimeOrderNo()); // 非加班委托单号
|
oldRecord.setAmount((Objects.isNull(oldRecord.getAmount()) ? 0 : oldRecord.getAmount()) + 1); // 非加班数量
|
oldRecord.setWorkTime(accuracy(manHour,oldRecord.getAmount())); // 非加班工时
|
oldRecord.setOutputWorkTime((Objects.isNull(oldRecord.getWorkTime()) ? 0 : oldRecord.getWorkTime()) +
|
(Objects.isNull(oldRecord.getOvertimeWorkTime()) ? 0 : oldRecord.getOvertimeWorkTime())); // 产量工时
|
}else {
|
// 加班
|
oldRecord.setOvertimeOrderNo(StringUtils.isNotEmpty(oldRecord.getOrderNo()) ? oldRecord.getOrderNo() : oldRecord.getOvertimeOrderNo()); // 加班委托单号
|
oldRecord.setOvertimeAmount((Objects.isNull(oldRecord.getOvertimeAmount()) ? 0 : oldRecord.getOvertimeAmount()) + 1); // 加班数量
|
oldRecord.setOvertimeWorkTime(accuracy(manHour,oldRecord.getOvertimeAmount())); // 加班工时
|
oldRecord.setOutputWorkTime((Objects.isNull(oldRecord.getWorkTime()) ? 0 : oldRecord.getWorkTime()) +
|
(Objects.isNull(oldRecord.getOvertimeWorkTime()) ? 0 : oldRecord.getOvertimeWorkTime())); // 产量工时
|
}
|
auxiliaryOutputWorkingHoursMapper.updateById(oldRecord);
|
}
|
}
|
}else {
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
DateTime parse = DateUtil.parse(LocalDateTime.now().format(formatter));
|
// 新增工时
|
AuxiliaryOutputWorkingHours addOutputWorkingHours = new AuxiliaryOutputWorkingHours();
|
BeanUtils.copyProperties(oldRecord, addOutputWorkingHours);
|
addOutputWorkingHours.setDateTime(date); // 日期
|
addOutputWorkingHours.setOvertimeOrderNo(auxiliaryOutputWorkingHours.getOvertimeOrderNo()); // 加班委托单号
|
addOutputWorkingHours.setOrderNo(auxiliaryOutputWorkingHours.getOrderNo()); // 非加班委托单号
|
addOutputWorkingHours.setId(null);
|
addOutputWorkingHours.setOutputWorkTime((ObjectUtils.isNotEmpty(auxiliaryOutputWorkingHours.getOvertimeWorkTime()) ?
|
auxiliaryOutputWorkingHours.getOvertimeWorkTime() : 0) +
|
(ObjectUtils.isNotEmpty(auxiliaryOutputWorkingHours.getWorkTime()) ? auxiliaryOutputWorkingHours.getWorkTime() : 0));//产量工时
|
addOutputWorkingHours.setWeekDay(getWeek(LocalDateTime.now().format(formatters)));//星期
|
addOutputWorkingHours.setCheckId(userId);//检测人
|
addOutputWorkingHours.setWeek(String.valueOf(DateUtil.weekOfYear(DateUtil.offsetDay(parse, 1))));//周次
|
if(isWithinRange) {
|
addOutputWorkingHours.setWorkTime(manHour.doubleValue()); // 非加班工时
|
addOutputWorkingHours.setOvertimeWorkTime(null);
|
addOutputWorkingHours.setAmount(1);//非加班数量
|
addOutputWorkingHours.setOvertimeAmount(null);//加班数量
|
}else {
|
addOutputWorkingHours.setOvertimeWorkTime(manHour.doubleValue()); // 加班工时
|
addOutputWorkingHours.setWorkTime(null);
|
addOutputWorkingHours.setOvertimeAmount(1);//加班数量
|
addOutputWorkingHours.setAmount(null);//非加班数量
|
}
|
|
List<InsProduct> insProducts = insProductMapper.selectList(new LambdaQueryWrapper<InsProduct>()
|
.eq(InsProduct::getInsSampleId, currentSampleId));
|
String inspectionItem = oldRecord.getInspectionItem();
|
String inspectionItemSubclass = oldRecord.getInspectionItemSubclass();
|
switch (inspectionItem) {
|
case "消振评估":
|
// 根据坐标来进行工时的添加
|
InsProductResult result1 = insProductResultMapper.selectOne(new LambdaQueryWrapper<InsProductResult>()
|
.eq(InsProductResult::getInsProductId, insProduct.getId()));
|
// 工时的个数
|
int count4 = 0;
|
if(!Objects.isNull(result1)) {
|
List<Map> maps = JSONArray.parseArray(result1.getInsValue(), Map.class);
|
// 根据坐标来进行分组
|
Map<Object, List<Map>> coordinate = maps.stream().collect(Collectors.groupingBy(item -> item.get("r")));
|
Iterator<Map.Entry<Object, List<Map>>> iterator = coordinate.entrySet().iterator();
|
while (iterator.hasNext()) {
|
Map.Entry<Object, List<Map>> entry = iterator.next();
|
List<Map> value = entry.getValue();
|
if(value.size() > count4) {
|
count4 = value.size();
|
}
|
}
|
}
|
Integer oldAmount4 = 0; // 已经添加的工时个数
|
for(AuxiliaryOutputWorkingHours a : oldRecords) {
|
oldAmount4 += (Objects.isNull(a.getAmount()) ? 0 : a.getAmount()) + (Objects.isNull(a.getOvertimeAmount()) ? 0 : a.getOvertimeAmount());
|
}
|
if(count4 > oldAmount4) {
|
auxiliaryOutputWorkingHoursMapper.insert(addOutputWorkingHours);
|
}
|
break;
|
case "温度循环":
|
int count = 0; // 工时的个数
|
if(CollectionUtils.isNotEmpty(insProducts)) {
|
for(InsProduct insProduct1 : insProducts) {
|
// 查询insProductResult拿到insValue的有值的个数
|
InsProductResult insProductResult = insProductResultMapper.selectOne(new LambdaQueryWrapper<InsProductResult>()
|
.eq(InsProductResult::getInsProductId, insProduct1.getId()));
|
if(!Objects.isNull(insProductResult)) {
|
// insProductResult不为空,获取有值的个数
|
List<Map> maps = JSONArray.parseArray(insProductResult.getInsValue(), Map.class);
|
for (Map map : maps) {
|
if (Strings.isNotEmpty(map.get("v").toString())) {
|
count++;
|
break;
|
}
|
}
|
}
|
}
|
}
|
Integer oldAmount = 0;
|
for(AuxiliaryOutputWorkingHours a : oldRecords) {
|
oldAmount += (Objects.isNull(a.getAmount()) ? 0 : a.getAmount()) + (Objects.isNull(a.getOvertimeAmount()) ? 0 : a.getOvertimeAmount());
|
}
|
if(count > oldAmount) {
|
auxiliaryOutputWorkingHoursMapper.insert(addOutputWorkingHours);
|
}
|
break;
|
case "单根垂直燃烧":
|
// 查看个数 是否与工时的个数一致,如果检验的个数大于工时的个数,那么就新增
|
int count1 = 0;
|
if(CollectionUtils.isNotEmpty(insProducts)) {
|
for(InsProduct insProduct1 : insProducts) {
|
// 查询insProductResult拿到insValue的有值的个数
|
InsProductResult insProductResult = insProductResultMapper.selectOne(new LambdaQueryWrapper<InsProductResult>()
|
.eq(InsProductResult::getInsProductId, insProduct1.getId()));
|
if(!Objects.isNull(insProductResult)) {
|
// insProductResult不为空,获取有值的个数
|
insProductResult.getInsValue();
|
List<Map> maps = JSONArray.parseArray(insProductResult.getInsValue(), Map.class);
|
for (Map map : maps) {
|
if (Strings.isNotEmpty(map.get("v").toString())) {
|
count1++;
|
}
|
}
|
}
|
}
|
}
|
Integer oldAmount1 = 0;
|
for(AuxiliaryOutputWorkingHours a : oldRecords) {
|
oldAmount1 += (Objects.isNull(a.getAmount()) ? 0 : a.getAmount()) + (Objects.isNull(a.getOvertimeAmount()) ? 0 : a.getOvertimeAmount());
|
}
|
if(count1 > oldAmount1) {
|
auxiliaryOutputWorkingHoursMapper.insert(addOutputWorkingHours);
|
}
|
break;
|
case "温升试验":
|
// 按照检验项分组 有几个检验值就算几次工时
|
Map<String, List<InsProduct>> collect = insProductMapper.selectList(new LambdaQueryWrapper<InsProduct>()
|
.eq(InsProduct::getSpecialItemParentId, parentInsProduct.getId()))
|
.stream()
|
.collect(Collectors.groupingBy(InsProduct::getInspectionItem));
|
int group = 0;
|
double oldWorkTime2 = 0; // 之前的工时
|
double oldAmount2 = 0; // 之前的数量
|
for(AuxiliaryOutputWorkingHours a : oldRecords) {
|
oldWorkTime2 += (Objects.isNull(a.getOvertimeWorkTime()) ? 0 : a.getOvertimeWorkTime()) + (Objects.isNull(a.getWorkTime()) ? 0 : a.getWorkTime());
|
oldAmount2+= (Objects.isNull(a.getAmount()) ? 0 : a.getAmount()) + (Objects.isNull(a.getOvertimeAmount()) ? 0 : a.getOvertimeAmount());
|
}
|
for (Map.Entry<String,List<InsProduct>> entry : collect.entrySet()) {
|
int minValue = Integer.MIN_VALUE;
|
List<InsProduct> insProducts1 = entry.getValue();
|
for (InsProduct product1 : insProducts1) {
|
InsProductResult insProductResult = insProductResultMapper.selectOne(Wrappers.<InsProductResult>lambdaQuery()
|
.eq(InsProductResult::getInsProductId, product1.getId()));
|
if(!Objects.isNull(insProductResult)) {
|
List<Map> maps = com.alibaba.fastjson2.JSON.parseArray(insProductResult.getInsValue(), Map.class);
|
// 最长的insValue 就有几组工时
|
if(maps.size() > minValue) {
|
minValue = maps.size();
|
}
|
}
|
}
|
if(minValue != Integer.MIN_VALUE) {
|
group += minValue;
|
}
|
}
|
// 检验的组数大于已经添加的组数就要更新工时
|
int oldGroup = 0;
|
if(manHour.doubleValue() != 0) {
|
oldGroup =(int) (oldWorkTime2 / manHour.doubleValue());
|
}
|
// 检验的组数大于已经添加的组数就要更新工时
|
if(group > oldGroup && group > oldAmount2) {
|
auxiliaryOutputWorkingHoursMapper.insert(addOutputWorkingHours);
|
}
|
break;
|
case "热循环":
|
// 按照检验项分组 有几个检验值就算几次工时
|
Map<String, List<InsProduct>> collect1 = new HashMap<>();
|
if(Objects.nonNull(parentInsProduct)){
|
collect1 = insProductMapper.selectList(new LambdaQueryWrapper<InsProduct>()
|
.eq(InsProduct::getSpecialItemParentId, parentInsProduct.getId()))
|
.stream()
|
.collect(Collectors.groupingBy(InsProduct::getInspectionItem));
|
}
|
int group1 = 0;
|
for (Map.Entry<String,List<InsProduct>> entry : collect1.entrySet()) {
|
int minValue = Integer.MIN_VALUE;
|
List<InsProduct> insProducts1 = entry.getValue();
|
for (InsProduct product1 : insProducts1) {
|
InsProductResult insProductResult = insProductResultMapper.selectOne(Wrappers.<InsProductResult>lambdaQuery()
|
.eq(InsProductResult::getInsProductId, product1.getId()));
|
if(!Objects.isNull(insProductResult)) {
|
List<Map> maps = com.alibaba.fastjson2.JSON.parseArray(insProductResult.getInsValue(), Map.class);
|
// 最长的insValue 就有几组工时
|
if(maps.size() > minValue) {
|
minValue = maps.size();
|
}
|
}
|
}
|
if(minValue != Integer.MIN_VALUE) {
|
group1 += minValue;
|
}
|
}
|
|
double oldWorkTime3 = 0; // 之前的工时
|
double oldAmount3 = 0; // 之前的数量
|
for(AuxiliaryOutputWorkingHours a : oldRecords) {
|
oldWorkTime3 += (Objects.isNull(a.getOvertimeWorkTime()) ? 0 : a.getOvertimeWorkTime()) + (Objects.isNull(a.getWorkTime()) ? 0 : a.getWorkTime());
|
oldAmount3+= (Objects.isNull(a.getAmount()) ? 0 : a.getAmount()) + (Objects.isNull(a.getOvertimeAmount()) ? 0 : a.getOvertimeAmount());
|
}
|
// 检验的组数大于已经添加的组数就要更新工时
|
int oldGroup1 = 0;
|
if(manHour.doubleValue() != 0) {
|
oldGroup1 =(int) (oldWorkTime3 / manHour.doubleValue());
|
}
|
// 检验的组数大于已经添加的组数就要更新工时
|
if((group1 > oldGroup1) && (group1 > oldAmount3)) {
|
auxiliaryOutputWorkingHoursMapper.insert(addOutputWorkingHours);
|
}
|
break;
|
}
|
|
if((inspectionItem.contains("松套管") || inspectionItemSubclass.contains("松套管") ||
|
!Objects.isNull(insProduct.getInsFiberId()) ||
|
!Objects.isNull(insProduct.getInsFibersId())) && Objects.isNull(insProduct.getSpecialItemParentId()) && !insProduct.getInspectionItem().equals("光纤接头损耗")) {
|
InsProduct product = insProductMapper.selectById(Integer.parseInt(k));
|
// 查询样品下面所有的松套管 并且过滤出检验项和检验子项相同的数据
|
List<InsProduct> collect = insProductMapper.selectList(new LambdaQueryWrapper<InsProduct>()
|
.eq(InsProduct::getInsSampleId, currentSampleId)
|
.and(item -> item.like(InsProduct::getInspectionItem, "松套管")
|
.or()
|
.like(InsProduct::getInspectionItemSubclass, "松套管")
|
.or()
|
.isNotNull(InsProduct::getInsFiberId)
|
.or()
|
.isNotNull(InsProduct::getInsFibersId))).stream()
|
.filter(item -> item.getInspectionItem().equals(product.getInspectionItem()) &&
|
item.getInspectionItemSubclass().equals(product.getInspectionItemSubclass()))
|
.collect(Collectors.toList());
|
// 检验总共的个数
|
int count = 0;
|
for (InsProduct insProduct1 : collect) {
|
// 查询result表
|
InsProductResult insProductResult = insProductResultMapper.selectOne(new LambdaQueryWrapper<InsProductResult>()
|
.eq(InsProductResult::getInsProductId, insProduct1.getId()));
|
// 去除当前检验项 如果有值则进行数量相加
|
if(Objects.isNull(insProductResult)) {
|
continue;
|
}
|
count++;
|
// List<Map> maps = JSONArray.parseArray(insProductResult.getInsValue(), Map.class);
|
// for(Map map : maps) {
|
// if(Strings.isNotEmpty(map.get("v").toString())) {
|
// count++;
|
// }
|
// }
|
}
|
// 工时的个数
|
Integer oldAmount = 0;
|
for(AuxiliaryOutputWorkingHours a : oldRecords) {
|
oldAmount += (Objects.isNull(a.getAmount()) ? 0 : a.getAmount()) + (Objects.isNull(a.getOvertimeAmount()) ? 0 : a.getOvertimeAmount());
|
}
|
// 输入的个数 大于 现有工时的个数才进行添加
|
if(count > oldAmount) {
|
auxiliaryOutputWorkingHoursMapper.insert(addOutputWorkingHours);
|
}
|
}
|
|
|
|
}
|
}
|
/**
|
* 精度问题 乘法
|
*/
|
public double accuracy(BigDecimal manHour, int count){
|
return manHour.multiply(BigDecimal.valueOf(count)).setScale(4, RoundingMode.HALF_UP).doubleValue();
|
}
|
/**
|
* 精度问题 加法
|
*/
|
public double addAccuracy(double manHour, double count){
|
return BigDecimal.valueOf(manHour).add(BigDecimal.valueOf(count)).setScale(4, RoundingMode.HALF_UP).doubleValue();
|
}
|
|
|
/**
|
* 查询检验项对应标准库配置的工时信息
|
* @param insProduct
|
* @return
|
*/
|
public StandardProductVO getInspectWorkHourAndGroup(InsProduct insProduct){
|
StandardProductVO standardProductVO = new StandardProductVO();
|
if(!Objects.isNull(insProduct)){
|
//查询对应标准库
|
List<StandardProductVO> productVO = standardProductListMapper.getStandardProductByInsProduct(
|
insProduct.getLaboratory(),
|
insProduct.getSampleType(),
|
insProduct.getSample(),
|
insProduct.getModel(),
|
insProduct.getInspectionItem(),
|
insProduct.getInspectionItemSubclass(),
|
insProduct.getSonLaboratory(),
|
insProduct.getStandardMethodListId());
|
if(!productVO.isEmpty()){
|
standardProductVO = productVO.get(0);
|
}
|
//有区间的检验项,取检验项存的工时信息
|
if(StringUtils.isNotBlank(insProduct.getSection()) && StringUtils.isNotBlank(standardProductVO.getSection())){
|
try {
|
ObjectMapper objectMapper = new ObjectMapper();
|
//区间设置
|
List<String> sectionList = (List<String>)objectMapper.readValue(standardProductVO.getSection(), List.class);
|
//选中区间的下标
|
int i = sectionList.indexOf(insProduct.getSection());
|
//获取对应下标的工时和工时分组
|
List<Double> hourList = (List<Double>)objectMapper.readValue(standardProductVO.getManHour(), List.class);
|
standardProductVO.setManHour(String.valueOf(hourList.get(i)));
|
} catch (JsonProcessingException e) {
|
throw new RuntimeException(e);
|
}
|
}
|
}
|
return standardProductVO;
|
}
|
|
|
public static String getWeek(String dayStr) {
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
try {
|
Date date = sdf.parse(dayStr);
|
Calendar calendar = Calendar.getInstance();
|
calendar.setTime(date);
|
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
|
int day = calendar.get(Calendar.DAY_OF_MONTH);
|
return getWeekDay(dayOfWeek);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return null;
|
}
|
|
public static String getWeekDay(int dayOfWeek) {
|
switch (dayOfWeek) {
|
case Calendar.MONDAY:
|
return "周一";
|
case Calendar.TUESDAY:
|
return "周二";
|
case Calendar.WEDNESDAY:
|
return "周三";
|
case Calendar.THURSDAY:
|
return "周四";
|
case Calendar.FRIDAY:
|
return "周五";
|
case Calendar.SATURDAY:
|
return "周六";
|
case Calendar.SUNDAY:
|
return "周日";
|
default:
|
return "未知";
|
}
|
}
|
|
}
|