|
@@ -1,31 +1,27 @@
|
|
|
package com.hssx.cloudmodel.service.impl;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.github.pagehelper.PageHelper;
|
|
|
-import com.github.pagehelper.PageInfo;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.hssx.cloudmodel.constant.Constant;
|
|
|
import com.hssx.cloudmodel.entity.*;
|
|
|
-import com.hssx.cloudmodel.entity.vo.MouldEquipmentVO;
|
|
|
import com.hssx.cloudmodel.entity.vo.MouldVO;
|
|
|
import com.hssx.cloudmodel.entity.vo.ProjectVO;
|
|
|
import com.hssx.cloudmodel.entity.vo.UserVO;
|
|
|
import com.hssx.cloudmodel.mapper.*;
|
|
|
-import com.hssx.cloudmodel.service.InjectionMoldingService;
|
|
|
import com.hssx.cloudmodel.service.MouldService;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.hssx.cloudmodel.util.*;
|
|
|
+import com.hssx.cloudmodel.util.GainTokenUtil;
|
|
|
+import com.hssx.cloudmodel.util.HttpRespMsg;
|
|
|
+import com.hssx.cloudmodel.util.ListUtil;
|
|
|
+import com.hssx.cloudmodel.util.WechatTemplateUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.commons.lang3.StringEscapeUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -70,16 +66,18 @@ public class MouldServiceImpl extends ServiceImpl<MouldMapper, Mould> implements
|
|
|
MouldHistoryTimeMapper mouldHistoryTimeMapper;
|
|
|
@Resource
|
|
|
PacketLossRecordMapper packetLossRecordMapper;
|
|
|
+ @Resource
|
|
|
+ MouldCycleRuntimeMapper mouldCycleRuntimeMapper;
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public HttpRespMsg addAndUpdateMould(Mould mould, User user, Integer dynamicId,InjectionMolding injectionMolding) {
|
|
|
+ public HttpRespMsg addAndUpdateMould(Mould mould, User user, Integer dynamicId, InjectionMolding injectionMolding) {
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
|
if (mould.getId() != null) {
|
|
|
//修改
|
|
|
Mould mou = mouldMapper.selectById(mould.getId());
|
|
|
Mould m = mouldMapper.selectOne(new QueryWrapper<Mould>().eq("model_no", mould.getModelNo()));
|
|
|
- if (mou.getModelNo().equals(mould.getModelNo()) || m == null){
|
|
|
+ if (mou.getModelNo().equals(mould.getModelNo()) || m == null) {
|
|
|
if (mould.getProduceCompanyId() != null) {
|
|
|
Company company = companyMapper.selectById(mould.getProduceCompanyId());
|
|
|
mould.setProduceCompanyName(company.getCompanyName());
|
|
@@ -225,7 +223,7 @@ public class MouldServiceImpl extends ServiceImpl<MouldMapper, Mould> implements
|
|
|
} else {
|
|
|
MouldVO mould = mouldMapper.getDetailById(mouldVO);
|
|
|
InjectionMolding molding = injectionMoldingMapper.selectOne(new QueryWrapper<InjectionMolding>().eq("mould_id", mouldVO.getId()));
|
|
|
- if(null != molding){
|
|
|
+ if (null != molding) {
|
|
|
mould.setInjectionMolding(molding);
|
|
|
}
|
|
|
map.put("vo", mould);
|
|
@@ -331,9 +329,9 @@ public class MouldServiceImpl extends ServiceImpl<MouldMapper, Mould> implements
|
|
|
uids.add(-1);
|
|
|
List<User> userList = userMapper.selectList(new QueryWrapper<User>().in("id", uids).isNotNull("openid").eq("is_disable", 1));
|
|
|
//公众号的推送to do
|
|
|
- userList.forEach(u ->{
|
|
|
+ userList.forEach(u -> {
|
|
|
try {
|
|
|
- WechatTemplateUtil.sendMaintainTemplateMessage(u.getOpenid(),mould.getModelNo()+"-"+mould.getModelName(),Constant.MAIN_TAIN_TYPE,Constant.MAIN_TAIN_CONTENT +sumCount+"次数",token);
|
|
|
+ WechatTemplateUtil.sendMaintainTemplateMessage(u.getOpenid(), mould.getModelNo() + "-" + mould.getModelName(), Constant.MAIN_TAIN_TYPE, Constant.MAIN_TAIN_CONTENT + sumCount + "次数", token);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
@@ -556,7 +554,7 @@ public class MouldServiceImpl extends ServiceImpl<MouldMapper, Mould> implements
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public HttpRespMsg changeMouldEquipment(Mould mould,Integer mouldId,String token) {
|
|
|
+ public HttpRespMsg changeMouldEquipment(Mould mould, Integer mouldId, String token) {
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
|
User currentUser = userMapper.selectOne(new QueryWrapper<User>().eq("head_imgurl", token));
|
|
|
if (currentUser != null) {
|
|
@@ -591,22 +589,22 @@ public class MouldServiceImpl extends ServiceImpl<MouldMapper, Mould> implements
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
|
Date now = new Date();
|
|
|
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:");
|
|
|
- int housTime = now.getDay()-1;
|
|
|
+ int housTime = now.getDay() - 1;
|
|
|
now.setDate(housTime);
|
|
|
String lastOpenTime = sdf1.format(now);
|
|
|
try {
|
|
|
- String lastOpenTimeDate = lastOpenTime+ "59:59";
|
|
|
+ String lastOpenTimeDate = lastOpenTime + "59:59";
|
|
|
List<MouldHistory> mouldHistorys = mouldHistoryMapper.selectListByTimeCondition(lastOpenTimeDate);
|
|
|
for (MouldHistory mouldHistory : mouldHistorys) {
|
|
|
Integer count = mouldHistoryTimeMapper.selectCount(new QueryWrapper<MouldHistoryTime>().eq("equipment_no", mouldHistory.getEquipmentNo()).lt("history_id", mouldHistory.getId()));
|
|
|
- if(!count .equals(mouldHistory.getRunCnt())){
|
|
|
+ if (!count.equals(mouldHistory.getRunCnt())) {
|
|
|
PacketLossRecord record = packetLossRecordMapper.selectOne(new QueryWrapper<PacketLossRecord>().eq("equipment_no", mouldHistory.getEquipmentNo()));
|
|
|
- if(record != null){
|
|
|
- record.setCount(mouldHistory.getRunCnt()-count);
|
|
|
+ if (record != null) {
|
|
|
+ record.setCount(mouldHistory.getRunCnt() - count);
|
|
|
packetLossRecordMapper.updateById(record);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
PacketLossRecord packRecord = new PacketLossRecord();
|
|
|
- packRecord.setCount(mouldHistory.getRunCnt()-count);
|
|
|
+ packRecord.setCount(mouldHistory.getRunCnt() - count);
|
|
|
packRecord.setEquipmentNo(mouldHistory.getEquipmentNo());
|
|
|
packetLossRecordMapper.insert(packRecord);
|
|
|
}
|
|
@@ -617,4 +615,40 @@ public class MouldServiceImpl extends ServiceImpl<MouldMapper, Mould> implements
|
|
|
}
|
|
|
return msg;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg updateRuntimesTask() {
|
|
|
+ List<MouldHistoryTime> list = mouldHistoryTimeMapper.selectListByTime(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
|
|
|
+ Map<String, List<MouldHistoryTime>> map = list.stream().collect(Collectors.groupingBy(MouldHistoryTime::getEquipmentNo));
|
|
|
+ for (Map.Entry<String, List<MouldHistoryTime>> stringListEntry : map.entrySet()) {
|
|
|
+ for (int i = 0; i < 24; i++) {
|
|
|
+ MouldCycleRuntime mr = new MouldCycleRuntime();
|
|
|
+ final int first = i;
|
|
|
+ final int second = i + 1;
|
|
|
+ List<MouldHistoryTime> collect = stringListEntry.getValue().stream().filter(x -> (x.getOpenTime().getHour() >= first && x.getOpenTime().getHour() < second)).collect(Collectors.toList());
|
|
|
+ System.out.println(collect);
|
|
|
+ System.out.println((int) stringListEntry.getValue().stream().filter(x -> x.getOpenTime().getHour() >= first && x.getOpenTime().getHour() < second).count());
|
|
|
+ mr.setRuntime((int) stringListEntry.getValue().stream().filter(x -> (x.getOpenTime().getHour() >= first && x.getOpenTime().getHour() < second)).count());
|
|
|
+ String iStr = i < 10 ? ("0" + i) : i + "";
|
|
|
+ int i1 = i + 1;
|
|
|
+ String iStrAfterOne = (i1) < 10 ? ("0" + i1) : i1 + "";
|
|
|
+ mr.setTimeSlot(iStr + ":00-" + iStrAfterOne + ":00");
|
|
|
+ if(!CollectionUtils.isEmpty(stringListEntry.getValue())){
|
|
|
+ mr.setDateStr(DateTimeFormatter.ofPattern("yyyy-MM-dd").format(stringListEntry.getValue().get(0).getOpenTime()));
|
|
|
+ }else{
|
|
|
+ mr.setDateStr(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
|
|
|
+ }
|
|
|
+ mr.setEquipmentNo(stringListEntry.getKey());
|
|
|
+ MouldCycleRuntime id = mouldCycleRuntimeMapper.selectOne(new QueryWrapper<MouldCycleRuntime>().eq("time_slot",mr.getTimeSlot()).eq("equipment_no",mr.getEquipmentNo()).eq("date_str",mr.getDateStr()).select("id"));
|
|
|
+ if (null != id) {
|
|
|
+ mr.setId(id.getId());
|
|
|
+ mouldCycleRuntimeMapper.updateById(mr);
|
|
|
+ } else {
|
|
|
+ mouldCycleRuntimeMapper.insert(mr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return new HttpRespMsg();
|
|
|
+ }
|
|
|
}
|
|
|
+
|