package cn.stylefeng.guns.modular.om.productionOrdeInfo.controller;
|
|
import cn.afterturn.easypoi.entity.vo.MapExcelConstants;
|
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
|
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
|
import cn.afterturn.easypoi.view.PoiBaseView;
|
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
|
import cn.stylefeng.guns.modular.om.productionOrdeInfo.entity.ProductionOrdeInfo;
|
import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.params.ProductionOrdeInfoParam;
|
import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.result.ProductionOrdeInfoResult;
|
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
|
import cn.stylefeng.guns.sys.modular.system.entity.Dict;
|
import cn.stylefeng.guns.sys.modular.system.service.DictService;
|
import cn.stylefeng.roses.core.base.controller.BaseController;
|
import cn.stylefeng.roses.kernel.model.response.ResponseData;
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.extension.api.R;
|
import io.swagger.models.auth.In;
|
import lombok.SneakyThrows;
|
import org.apache.poi.hssf.usermodel.HSSFCell;
|
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
|
import org.apache.poi.ss.usermodel.Cell;
|
import org.apache.poi.xssf.usermodel.XSSFCell;
|
import org.apache.poi.xssf.usermodel.XSSFRow;
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.ui.ModelMap;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.IOException;
|
import java.text.DecimalFormat;
|
import java.text.NumberFormat;
|
import java.text.SimpleDateFormat;
|
import java.time.LocalDate;
|
import java.util.*;
|
|
|
/**
|
* 生产工单控制器
|
*
|
* @author cl
|
* @Date 2022-10-25 14:04:47
|
*/
|
@Controller
|
@RequestMapping("/productionOrdeInfo")
|
public class ProductionOrdeInfoController extends BaseController {
|
|
private String PREFIX = "modular/om/productionOrdeInfo";
|
|
@Autowired
|
private ProductionOrdeInfoService productionOrdeInfoService;
|
|
@Autowired
|
private DictService dictService;
|
|
/**
|
* 跳转到主页面
|
*
|
* @author cl
|
* @Date 2022-10-25
|
*/
|
@RequestMapping("")
|
public String index() {
|
return PREFIX + "/productionOrdeInfo.html";
|
}
|
|
/**
|
* 新增页面
|
*
|
* @author cl
|
* @Date 2022-10-25
|
*/
|
@RequestMapping("/add")
|
public String add() {
|
return PREFIX + "/productionOrdeInfo_add.html";
|
}
|
|
/**
|
* 编辑页面
|
*
|
* @author cl
|
* @Date 2022-10-25
|
*/
|
@RequestMapping("/edit")
|
public String edit() {
|
return PREFIX + "/productionOrdeInfo_edit.html";
|
}
|
|
@RequestMapping("/materialList")
|
public String materialList() {
|
return PREFIX + "/materialList.html";
|
}
|
|
@RequestMapping("/materialLists")
|
public String materialLists() {
|
return PREFIX + "/materialLists.html";
|
}
|
|
@RequestMapping("/customInfo")
|
public String customInfo() {
|
return PREFIX + "/customInfo.html";
|
}
|
|
/**
|
* 新增接口
|
*
|
* @author cl
|
* @Date 2022-10-25
|
*/
|
@RequestMapping("/addItem")
|
@ResponseBody
|
public ResponseData addItem(ProductionOrdeInfoParam productionOrdeInfoParam) {
|
this.productionOrdeInfoService.add(productionOrdeInfoParam);
|
return ResponseData.success();
|
}
|
|
/**
|
* 编辑接口
|
*
|
* @author cl
|
* @Date 2022-10-25
|
*/
|
@RequestMapping("/editItem")
|
@ResponseBody
|
public ResponseData editItem(ProductionOrdeInfoParam productionOrdeInfoParam) {
|
if(productionOrdeInfoParam.getFlag()!=null){
|
productionOrdeInfoParam.setActualStartTime(new Date());
|
}
|
this.productionOrdeInfoService.update(productionOrdeInfoParam);
|
this.productionOrdeInfoService.saveOrderBatchInfo(productionOrdeInfoParam);
|
return ResponseData.success();
|
}
|
|
/**
|
* 编辑接口
|
*
|
* @author cl
|
* @Date 2022-10-25
|
*/
|
@RequestMapping("/editItemAll")
|
@ResponseBody
|
public ResponseData editItemAll(@RequestBody List<ProductionOrdeInfoParam> list) {
|
for(int i=0;i<list.size();i++){
|
ProductionOrdeInfoParam productionOrdeInfoParam = list.get(i);
|
this.productionOrdeInfoService.update(productionOrdeInfoParam);
|
}
|
|
return ResponseData.success();
|
}
|
|
/**
|
* 删除接口
|
*
|
* @author cl
|
* @Date 2022-10-25
|
*/
|
@RequestMapping("/delete")
|
@ResponseBody
|
public ResponseData delete(ProductionOrdeInfoParam productionOrdeInfoParam) {
|
this.productionOrdeInfoService.delete(productionOrdeInfoParam);
|
return ResponseData.success();
|
}
|
|
/**
|
* 查看详情接口
|
*
|
* @author cl
|
* @Date 2022-10-25
|
*/
|
@RequestMapping("/detail")
|
@ResponseBody
|
public ResponseData detail(ProductionOrdeInfoParam productionOrdeInfoParam) {
|
ProductionOrdeInfo detail = this.productionOrdeInfoService.getById(productionOrdeInfoParam.getId());
|
return ResponseData.success(detail);
|
}
|
|
/**
|
* 查询列表
|
*
|
* @author cl
|
* @Date 2022-10-25
|
*/
|
@ResponseBody
|
@CrossOrigin
|
@RequestMapping("/list")
|
public LayuiPageInfo list(ProductionOrdeInfoParam productionOrdeInfoParam) {
|
return this.productionOrdeInfoService.findPageBySpec(productionOrdeInfoParam);
|
}
|
|
@ResponseBody
|
@RequestMapping("/orderCount")
|
public ResponseData orderCount(ProductionOrdeInfoParam productionOrdeInfoParam) {
|
int orderStatus = productionOrdeInfoService.count(new QueryWrapper<ProductionOrdeInfo>().eq("order_status", productionOrdeInfoParam.getOrderStatus()));
|
return ResponseData.success(orderStatus);
|
}
|
|
/**
|
* 大屏列表接口
|
* @param productionOrdeInfoParam
|
* @return
|
*/
|
@ResponseBody
|
@CrossOrigin
|
@RequestMapping("/largeScreenList")
|
public List largeScreenList(ProductionOrdeInfoParam productionOrdeInfoParam) {
|
ArrayList arrayList = new ArrayList();
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
// productionOrdeInfoParam.setOrderStatus("3");
|
LayuiPageInfo pageBySpec = this.productionOrdeInfoService.findPageBySpec(productionOrdeInfoParam);
|
List<ProductionOrdeInfoResult> result = pageBySpec.getData();
|
for (ProductionOrdeInfoResult productionOrdeInfoResult : result) {
|
ArrayList resultList = new ArrayList();
|
resultList.add(productionOrdeInfoResult.getWorkOrderNo());
|
resultList.add(productionOrdeInfoResult.getMaterialCode());
|
resultList.add(productionOrdeInfoResult.getProductionLine());
|
resultList.add(productionOrdeInfoResult.getPlanQty());
|
resultList.add(productionOrdeInfoResult.getActualQty());
|
resultList.add(format.format(productionOrdeInfoResult.getCreateTime()));
|
arrayList.add(resultList);
|
}
|
return arrayList;
|
}
|
|
@ResponseBody
|
@CrossOrigin
|
@RequestMapping("/largeScreenList1")
|
public List largeScreenList1(ProductionOrdeInfoParam productionOrdeInfoParam) {
|
ArrayList arrayList = new ArrayList();
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
List<ProductionOrdeInfoResult> list = this.productionOrdeInfoService.getListMonth();
|
for (ProductionOrdeInfoResult productionOrdeInfoResult : list) {
|
ArrayList resultList = new ArrayList();
|
resultList.add(productionOrdeInfoResult.getWorkOrderNo());
|
resultList.add(productionOrdeInfoResult.getMaterialCode());
|
resultList.add(productionOrdeInfoResult.getPlanQty());
|
resultList.add(productionOrdeInfoResult.getActualQty());
|
resultList.add(format.format(productionOrdeInfoResult.getCreateTime()));
|
arrayList.add(resultList);
|
}
|
return arrayList;
|
}
|
|
/**
|
* 大屏产线接口
|
* @return
|
*/
|
@ResponseBody
|
@CrossOrigin
|
@RequestMapping("/lineFinishQty")
|
public ResponseData lineFinishQty() {
|
List list = this.productionOrdeInfoService.lineFinishQty();
|
return ResponseData.success(list);
|
}
|
|
/**
|
* 大屏车间工单信息接口
|
* @return
|
*/
|
@ResponseBody
|
@CrossOrigin
|
@RequestMapping("/workshopOrderDetail")
|
public ResponseData workshopOrderDetail(ProductionOrdeInfoParam productionOrdeInfoParam) {
|
NumberFormat numberFormat = NumberFormat.getInstance();
|
numberFormat.setMaximumFractionDigits(2);
|
ProductionOrdeInfo one = productionOrdeInfoService.getOne(new QueryWrapper<ProductionOrdeInfo>()
|
.select("SUM\n" +
|
"\t( plan_qty ) AS planQty,\n" +
|
"\tSUM ( actual_qty ) AS actualQty,\n" +
|
"\tSUM ( scrap_qty ) AS scrapQty ")
|
);
|
//计划
|
Integer plqnQty = one.getPlanQty();
|
//完成
|
Integer actualQty = one.getActualQty();
|
//报废
|
Integer scrapQty = one.getScrapQty();
|
//合格数量
|
Integer paseQty = actualQty-scrapQty;
|
|
Map map = new HashMap<String,String>();
|
map.put("produceQty",plqnQty);
|
map.put("finishQty",actualQty);
|
map.put("paseQty",paseQty);
|
map.put("noPaseQty",scrapQty);
|
map.put("CompletionRate",numberFormat.format((float) actualQty / (float) plqnQty * 100));
|
map.put("PassRate",numberFormat.format((float) paseQty / (float) actualQty * 100));
|
map.put("surplusQty",plqnQty-actualQty);
|
return ResponseData.success(map);
|
}
|
|
/**
|
* 大屏车间工单信息接口
|
* @return
|
*/
|
@ResponseBody
|
@CrossOrigin
|
@RequestMapping("/reportLineList")
|
public ResponseData reportLineList(ProductionOrdeInfoParam productionOrdeInfoParam) {
|
Map map = new HashMap<String,String>();
|
return ResponseData.success(map);
|
}
|
|
@ResponseBody
|
@CrossOrigin
|
@RequestMapping("/lineChart")
|
public ResponseData lineChart(ProductionOrdeInfoParam productionOrdeInfoParam) {
|
List<String> list = new ArrayList();
|
List<Integer> planQtyList = new ArrayList();
|
List<Integer> actualQtyList = new ArrayList();
|
Map map = new HashMap<String,String>();
|
// for (int i = 0; i < 7; i++) {
|
// String str = LocalDate.now().minusDays(i).toString();
|
for (Object o : getWeek()) {
|
QueryWrapper<ProductionOrdeInfo> queryWrapper = new QueryWrapper<ProductionOrdeInfo>();
|
queryWrapper.select("SUM(plan_qty) as planQty,SUM(actual_qty) as actualQty");
|
queryWrapper.apply("CONVERT ( VARCHAR ( 100 ), plan_start_time, 23 ) = {0}",o.toString() );
|
ProductionOrdeInfo one = productionOrdeInfoService.getOne(queryWrapper);
|
if(one!=null){
|
if(one.getPlanQty()!=null){
|
planQtyList.add(one.getPlanQty());
|
}else {
|
planQtyList.add(0);
|
}
|
if(one.getActualQty()!=null){
|
actualQtyList.add(one.getActualQty());
|
}else {
|
actualQtyList.add(0);
|
}
|
}else {
|
planQtyList.add(0);
|
actualQtyList.add(0);
|
}
|
list.add(o.toString());
|
}
|
|
// }
|
map.put("category",list);
|
map.put("lineData",planQtyList);
|
map.put("barData",actualQtyList);
|
return ResponseData.success(map);
|
}
|
|
public static void main(String[] args) {
|
// List<String> weeks = getFormatDate("month");
|
// System.out.println(JSONObject.toJSONString(weeks));
|
// for (int i = 0; i < 7; i++) {
|
// System.out.println(LocalDate.now().minusDays(i));
|
// }
|
System.out.println(getWeek());
|
|
}
|
public static List getWeek(){
|
List<String> list = new ArrayList<>();
|
list.add(LocalDate.now().minusDays(6).toString());
|
list.add(LocalDate.now().minusDays(5).toString());
|
list.add(LocalDate.now().minusDays(4).toString());
|
list.add(LocalDate.now().minusDays(3).toString());
|
list.add(LocalDate.now().minusDays(2).toString());
|
list.add(LocalDate.now().minusDays(1).toString());
|
list.add(LocalDate.now().minusDays(0).toString());
|
return list;
|
}
|
|
|
/**
|
* 下载excel导入模板
|
*
|
* @author liwenya
|
* @Date 2021年7月9日 17点01分
|
*/
|
@RequestMapping("/downloadExcelTemplate")
|
public void downloadExcelTemplate(ModelMap modelMap, HttpServletRequest request,
|
HttpServletResponse response) {
|
//初始化表头
|
List<ExcelExportEntity> entity = new ArrayList<>();
|
entity.add(new ExcelExportEntity("生产工单号", "workOrderNo"));
|
entity.add(new ExcelExportEntity("物料编号", "materialCode"));
|
entity.add(new ExcelExportEntity("物料描述", "materialName"));
|
|
entity.add(new ExcelExportEntity("软件版本编码", "softwareVersionCode"));
|
entity.add(new ExcelExportEntity("生产基地编码", "productCompanyCode"));
|
|
entity.add(new ExcelExportEntity("计划数量", "planQty"));
|
entity.add(new ExcelExportEntity("计划开始时间", "planStartTime"));
|
entity.add(new ExcelExportEntity("计划结束时间", "planEndTime"));
|
|
ExportParams params = new ExportParams("生产工单模板", "生产工单", ExcelType.XSSF);
|
modelMap.put(MapExcelConstants.MAP_LIST, new ArrayList<>());
|
modelMap.put(MapExcelConstants.ENTITY_LIST, entity);
|
modelMap.put(MapExcelConstants.PARAMS, params);
|
modelMap.put(MapExcelConstants.FILE_NAME, "生产工单");
|
PoiBaseView.render(modelMap, request, response, MapExcelConstants.EASYPOI_MAP_EXCEL_VIEW);
|
}
|
|
/**
|
* 导入Excel
|
*
|
* @author cl
|
* @Date 2022-10-25
|
*/
|
@SneakyThrows
|
@RequestMapping("/uploadExcel")
|
@ResponseBody
|
public ResponseData exportIn(@RequestPart("file") MultipartFile file, HttpServletRequest request){
|
List<ProductionOrdeInfo> list = new ArrayList<>();
|
|
//定义工作簿
|
XSSFWorkbook sheets = null;
|
try{
|
sheets = new XSSFWorkbook(file.getInputStream());
|
//获取sheet
|
XSSFSheet sheet = sheets.getSheet(sheets.getSheetName(0));
|
int rows = sheet.getPhysicalNumberOfRows();
|
for(int i = 2; i < rows; i++){
|
//获取列数
|
XSSFRow row = sheet.getRow(i);
|
ProductionOrdeInfo orderInfo = new ProductionOrdeInfo();
|
|
orderInfo.setWorkOrderNo(getCellValue(row.getCell(0)));//工单编码
|
orderInfo.setMaterialCode(getCellValue(row.getCell(1)));//物料编号
|
orderInfo.setMaterialName(getCellValue(row.getCell(2)));//物料描述
|
|
orderInfo.setSoftwareVersionCode(getCellValue(row.getCell(3)));//软件版本编码
|
orderInfo.setProductCompanyCode(getCellValue(row.getCell(4)));//生产基地编码
|
|
|
Cell planQty = row.getCell(5);//计划数量
|
if(!Objects.equals(planQty, null) && !Objects.equals(planQty.toString(),"")){
|
double d = planQty.getNumericCellValue();
|
orderInfo.setPlanQty((int) d);
|
}
|
|
Cell planStartTime = row.getCell(6);//计划开始时间
|
if(HSSFDateUtil.isCellDateFormatted(planStartTime)){
|
Date d = planStartTime.getDateCellValue();
|
orderInfo.setPlanStartTime(d);
|
}
|
|
Cell planEndTime = row.getCell(7);//计划结束时间
|
if(HSSFDateUtil.isCellDateFormatted(planEndTime)){
|
Date d = planEndTime.getDateCellValue();
|
orderInfo.setPlanEndTime(d);
|
}
|
list.add(orderInfo);
|
}
|
|
for(ProductionOrdeInfo obj : list){
|
productionOrdeInfoService.save(obj);
|
}
|
return ResponseData.success("上传成功");
|
} catch (IOException e) {
|
e.printStackTrace();
|
return ResponseData.error("上传失败");
|
}
|
}
|
|
|
/**
|
* 获得Hsscell内容
|
*
|
* @param cell
|
* @return
|
*/
|
public String getCellValue(XSSFCell cell) {
|
String value = "";
|
if (cell != null) {
|
switch (cell.getCellType()) {
|
case HSSFCell.CELL_TYPE_FORMULA:
|
break;
|
case HSSFCell.CELL_TYPE_NUMERIC:
|
DecimalFormat df = new DecimalFormat("0");
|
value = df.format(cell.getNumericCellValue());
|
break;
|
case HSSFCell.CELL_TYPE_STRING:
|
value = cell.getStringCellValue().trim();
|
break;
|
default:
|
value = "";
|
break;
|
}
|
}
|
return value.trim();
|
}
|
|
}
|