package cn.stylefeng.guns.modular.cm.passingStationCollection.service.impl; import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory; import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo; import cn.stylefeng.guns.modular.bs.equipmentInfo.model.params.EquipmentInfoParam; import cn.stylefeng.guns.modular.bs.equipmentInfo.model.result.EquipmentInfoResult; import cn.stylefeng.guns.modular.cm.passingStationCollection.entity.PassingStationCollection; import cn.stylefeng.guns.modular.cm.passingStationCollection.mapper.PassingStationCollectionMapper; import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam; import cn.stylefeng.guns.modular.cm.passingStationCollection.model.result.PassingStationCollectionResult; import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService; import cn.stylefeng.roses.core.util.ToolUtil; 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.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.io.Serializable; import java.text.DecimalFormat; import java.text.NumberFormat; import java.text.SimpleDateFormat; import java.util.*; import java.util.concurrent.TimeUnit; /** *

* 产品过站采集 服务实现类 *

* * @author zrm * @since 2023-02-11 */ @Service public class PassingStationCollectionServiceImpl extends ServiceImpl implements PassingStationCollectionService { @Autowired private PassingStationCollectionService passingService; private static SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); @Override public void add(PassingStationCollectionParam param){ PassingStationCollection entity = getEntity(param); // try{ // String beatTime = getDistanceTime(df.format(param.getOutboundTime()), df.format(param.getInboundTime())); // entity.setBeatTime(beatTime); // }catch (Exception e){ // e.printStackTrace(); // } this.save(entity); } @Override public void delete(PassingStationCollectionParam param){ this.removeById(getKey(param)); } @Override public void update(PassingStationCollectionParam param){ PassingStationCollection oldEntity = getOldEntity(param); PassingStationCollection newEntity = getEntity(param); ToolUtil.copyProperties(newEntity, oldEntity); this.updateById(newEntity); } @Override public PassingStationCollectionResult findBySpec(PassingStationCollectionParam param){ return null; } @Override public List findListBySpec(PassingStationCollectionParam param){ return null; } @Override public LayuiPageInfo findPageBySpec(PassingStationCollectionParam param){ Page pageContext = getPageContext(); IPage page = this.baseMapper.customPageList(pageContext, param); List result = page.getRecords(); for (PassingStationCollectionResult passingStationCollectionResult : result) { try { String beatTime = getDistanceTime(df.format(passingStationCollectionResult.getOutboundTime()), df.format(passingStationCollectionResult.getInboundTime())); if(beatTime.contains("-")){ passingStationCollectionResult.setBeatTime("数据异常"); }else { passingStationCollectionResult.setBeatTime(beatTime); } }catch (Exception e){ } } return LayuiPageFactory.createPageInfo(page); } @Override public LayuiPageInfo PassRate(PassingStationCollectionParam param) { Page pageContext = getPageContext(); IPage page = this.baseMapper.PassRate(pageContext, param); return LayuiPageFactory.createPageInfo(page); } @Override public List snCodeSize(String str) { return this.baseMapper.snCodeSize(str); } @Override public PassingStationCollectionResult getMaxSnCode() { return this.baseMapper.getMaxSnCode(); } @Override public List getBeatTimeList(String sfcCode) { return this.baseMapper.getBeatTimeList(sfcCode); } @Override public List bottomLeftChart2() { return this.baseMapper.bottomLeftChart2(); } @Override public Integer getRepairQty() { return baseMapper.getRepairQty(); } @Override public Integer getRepairQtyWeek() { return baseMapper.getRepairQtyWeek(); } @Override public LayuiPageInfo passingPassRateList(PassingStationCollectionParam passingStationCollectionParam) { List resultList = new ArrayList(); QueryWrapper wrapper = new QueryWrapper(); wrapper.select("location_code"); if(passingStationCollectionParam.getStartTime()!=null){ wrapper.between("collection_time",passingStationCollectionParam.getStartTime(),passingStationCollectionParam.getEndTime()); } wrapper.groupBy("location_code"); List locationCode = passingService.list(wrapper); for (PassingStationCollection passingStationCollection : locationCode) { Map map = new HashMap(); int int1 = passingService.count(new QueryWrapper() .eq("location_code", passingStationCollection.getLocationCode()) .eq("out_rs_sign", "1") ); int int2 = passingService.count(new QueryWrapper() .eq("location_code", passingStationCollection.getLocationCode()) .eq("out_rs_sign", "2") ); map.put("locationCode",passingStationCollection.getLocationCode()); map.put("qualified",int1); map.put("unqualified",int2); DecimalFormat df = new DecimalFormat("0.00%"); if(int2 == 0){ map.put("passRate","100%"); }else { Integer count = int1+int2; double c = (double)int1/count; map.put("passRate",df.format(c)); } resultList.add(map); } LayuiPageInfo result = new LayuiPageInfo(); result.setCount(resultList.size()); result.setData(resultList); return result; } private Serializable getKey(PassingStationCollectionParam param){ return param.getId(); } private Page getPageContext() { return LayuiPageFactory.defaultPage(); } private PassingStationCollection getOldEntity(PassingStationCollectionParam param) { return this.getById(getKey(param)); } private PassingStationCollection getEntity(PassingStationCollectionParam param) { PassingStationCollection entity = new PassingStationCollection(); ToolUtil.copyProperties(param, entity); return entity; } public static String getDistanceTime(String str1, String str2) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date one; Date two; long day = 0;//天数差 long hour = 0;//小时数差 long min = 0;//分钟数差 long second=0;//秒数差 long diff=0 ;//毫秒差 String result = ""; try { final Calendar c = Calendar.getInstance(); c.setTimeZone(TimeZone.getTimeZone("GMT+8:00")); one = df.parse(str1); c.setTime(one); two = df.parse(str2); long time2 = one.getTime(); long time1 = two.getTime(); diff = time2 - time1; day = diff / (24 * 60 * 60 * 1000); hour = (diff / (60 * 60 * 1000) - day * 24); min = ((diff / (60 * 1000)) - day * 24 * 60 - hour * 60); second = diff/1000; System.out.println("day="+day+" hour="+hour+" min="+min+" ss="+second%60+" SSS="+diff%1000); String daystr = day%30+"天"; String hourStr = hour%24+"小时"; String minStr = min%60+"分"; Integer intHourStr = Integer.valueOf(hourStr.substring(0,1))*60; Integer intMinStr = Integer.valueOf(minStr.substring(0,1)); System.out.println(intHourStr+intMinStr); String secondStr = second%60+"秒"; if (day!=0){ result = result + daystr; } if (hour!=0){ result = result + hourStr; } if (min!=0){ result = result + minStr; } if (second!=0){ result = result + secondStr; } } catch (Exception e) { e.printStackTrace(); } return String.valueOf(second); } @Override public int updateSFC(String sfcCode, String childSfcCode) { return this.baseMapper.updateSFC(sfcCode, childSfcCode); } @Override public List exportTable(PassingStationCollectionParam param) { List results = baseMapper.customList(param); for (PassingStationCollectionResult result : results) { if(result.getInboundTime()!=null&&result.getOutboundTime()!=null){ String beatTime = getDistanceTime(df.format(result.getOutboundTime()), df.format(result.getInboundTime())); result.setBeatTime(beatTime); } if(result.getOutRsSign().equals("1")){ result.setOutRsSign("合格"); }else { result.setOutRsSign("不合格"); } } return results; } }