package cn.stylefeng.guns.modular.kb.greaseBoard; import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo; import cn.stylefeng.guns.modular.gm.greaseManage.entity.GreaseManage; import cn.stylefeng.guns.modular.gm.greaseManage.model.params.GreaseManageParam; import cn.stylefeng.guns.modular.gm.greaseManage.model.result.GreaseManageResult; import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService; import cn.stylefeng.guns.modular.kb.utils.IPUtil; import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.result.ProductionOrdeInfoResult; import cn.stylefeng.guns.modular.sc.kanbanConf.model.params.KanbanConfParam; import cn.stylefeng.guns.modular.sc.kanbanConf.service.KanbanConfService; import cn.stylefeng.guns.plcserver.opc.unit.OPCUnit; import cn.stylefeng.roses.core.base.controller.BaseController; import cn.stylefeng.roses.kernel.model.response.ResponseData; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import javafx.stage.Stage; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; import java.util.*; /** * 返修上线看板 * * @author cl * @Date 2022-10-27 15:50:56 */ @Controller @RequestMapping("/greaseBoard") public class GreaseBoardController extends BaseController { private String PREFIX = "modular/kb/greaseBoard"; @Autowired private KanbanConfService kanbanConfService; @Autowired private GreaseManageService greaseManageService; /** * 跳转到主页面 * * @author cl * @Date 2022-10-27 */ @RequestMapping("") public String index() { return PREFIX + "/greaseBoard.html"; } /** * 新增看板配置页面 * * @author cl * @Date 2022-10-31 */ @RequestMapping("/add") public String add() { return PREFIX + "/kanbanConf_add.html"; } /** * 编辑页面 * * @author cl * @Date 2022-10-31 */ @RequestMapping("/edit") public String edit() { return PREFIX + "/kanbanConf_edit.html"; } @RequestMapping("/orderEdit") public String orderEdit() { return PREFIX + "/kanbanConf_orderEdit.html"; } /** * 新增接口 * * @author cl * @Date 2022-10-31 */ @RequestMapping("/addKanBanConfItem") @ResponseBody public ResponseData addItem(KanbanConfParam kanbanConfParam, HttpServletRequest request) { String realIp = IPUtil.getRealIp(request); kanbanConfParam.setIpAddress(realIp); kanbanConfParam.setWarehouseCode(kanbanConfParam.getScrapReason()); kanbanConfParam.setWarehouseName(kanbanConfParam.getScrapCategory()); this.kanbanConfService.add(kanbanConfParam); return ResponseData.success(); } /** * 新增接口 * MIGICC17500E00136V250WX23K03A0003B * @author cl * @Date 2022-10-31 */ @RequestMapping("/updategreaseManage") @ResponseBody public ResponseData updategreaseManage(GreaseManageParam greaseManageParam) { SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); String currentDate = format.format(new Date()); String barCode = greaseManageParam.getBarcode(); String lastTwelveChars = barCode.substring(barCode.length() - 12); String locationCode = getLocationCode(lastTwelveChars); String DuaDate = getDuaDate(lastTwelveChars); GreaseManage greaseManage = new GreaseManage(); greaseManage.setBarcode(barCode); greaseManage.setLocationCode(locationCode); greaseManage.setDuaDate(DuaDate); greaseManage.setDaysRemaining(getRemainder(currentDate,DuaDate)); greaseManage.setCreateTime(new Date()); greaseManage.setCreateUser("admin"); // greaseManageService.save(greaseManage); greaseManageService.update(greaseManage,new LambdaQueryWrapper().eq(GreaseManage::getLocationCode, locationCode)); return ResponseData.success(); } @ResponseBody @CrossOrigin @RequestMapping("/bigListGreaseBoard") public ResponseData orderDescListFive() { SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); String currentDate = format.format(new Date()); List list = new ArrayList(); List results = greaseManageService.list(); for (GreaseManage result : results) { String DuaDate = result.getDuaDate(); String remainder = getRemainder(currentDate, DuaDate); if(Integer.valueOf(remainder)<=90){ List itemList = new ArrayList(); itemList.add(boldText(result.getLocationCode())); itemList.add(boldText(DuaDate)); itemList.add(boldText(remainder)); list.add(itemList); }else { List itemList = new ArrayList(); itemList.add(whiteBoldText(result.getLocationCode())); itemList.add(whiteBoldText(DuaDate)); itemList.add(whiteBoldText(remainder)); list.add(itemList); } } return ResponseData.success(list); } @ResponseBody @CrossOrigin @RequestMapping("/testhandleOilState") public long handleOilState(){ SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); String currentDate = format.format(new Date()); GreaseManageParam param = new GreaseManageParam(); param.setLocationCode("OP050"); List list = greaseManageService.findListBySpec(param); if(list.size()>0) { String duaDate = list.get(0).getDuaDate(); // long daysBetween = Long.parseLong(getRemainder(currentDate,duaDate)); // long daysBetween = ChronoUnit.DAYS.between(date1, date2); // return daysBetween; } return 0; } public static String boldText(String param){ return ""+param+""; } public static String whiteBoldText(String param){ return ""+param+""; } public static void main(String[] args) { DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyyMMdd"); SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); String format1 = format.format(new Date()); System.out.println("Difference in days: " + getRemainder("20231215",format1)); } public static String getRemainder(String currentDate,String tableDate){ DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyyMMdd"); LocalDate localDate1 = LocalDate.parse(currentDate, dateFormatter); LocalDate localDate2 = LocalDate.parse(tableDate, dateFormatter); long days = ChronoUnit.DAYS.between(localDate1, localDate2); return String.valueOf(days); } public static String getDuaDate(String str){ String year = str.substring(1,3); String month = getMonth(str.substring(3,4)); String day = str.substring(4,6); return "20"+year+month+day; } public static String getLocationCode(String str){ String locationCode = ""; switch (str.substring(0,1)) { case "X": locationCode = "DOP020"; break; case "Y": locationCode = "OP050"; break; case "Z": locationCode = "BOP030/040"; break; default: break; } return locationCode; } public static String getMonth(String str){ String Month = ""; switch (str) { case "A": Month = "1"; break; case "B": Month = "2"; break; case "C": Month = "3"; break; case "D": Month = "4"; break; case "E": Month = "5"; break; case "F": Month = "6"; break; case "G": Month = "7"; break; case "H": Month = "8"; break; case "I": Month = "9"; break; case "J": Month = "10"; break; case "K": Month = "11"; break; case "L": Month = "12"; break; default: break; } return Month; } /** * 编辑接口 * * @author cl * @Date 2022-10-31 */ @RequestMapping("/editKanBanConfItem") @ResponseBody public ResponseData editItem(KanbanConfParam kanbanConfParam) { this.kanbanConfService.update(kanbanConfParam); return ResponseData.success(); } /** * 查询列表 * * @author cl * @Date 2022-10-31 */ @ResponseBody @RequestMapping("/qryKBConflist") public LayuiPageInfo list(KanbanConfParam kanbanConfParam, HttpServletRequest request) { String realIp = IPUtil.getRealIp(request); kanbanConfParam.setIpAddress(realIp); return this.kanbanConfService.findPageBySpec(kanbanConfParam); } }