|
@@ -0,0 +1,245 @@
|
|
|
+package com.ruoyi.project.production.controller;
|
|
|
+
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGUpdateStatement;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.ruoyi.project.plant.domain.TMtdDaily;
|
|
|
+import com.ruoyi.project.plant.domain.TMtdItem;
|
|
|
+import com.ruoyi.project.plant.mapper.TMtdItemMapper;
|
|
|
+import com.ruoyi.project.plant.service.ITMtdDailyService;
|
|
|
+import com.ruoyi.project.production.domain.TPrdRecordItem;
|
|
|
+import com.ruoyi.project.production.mapper.TPrdRecordItemMapper;
|
|
|
+import com.ruoyi.project.production.mapper.TPrdRecordMapper;
|
|
|
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
|
|
+import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
|
|
+import org.apache.poi.xwpf.usermodel.XWPFRun;
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.PutMapping;
|
|
|
+import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
|
|
+import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
|
|
|
+import com.ruoyi.project.production.domain.TPrdRecord;
|
|
|
+import com.ruoyi.project.production.service.ITPrdRecordService;
|
|
|
+import com.ruoyi.framework.web.controller.BaseController;
|
|
|
+import com.ruoyi.framework.web.domain.AjaxResult;
|
|
|
+import com.ruoyi.common.utils.poi.ExcelUtil;
|
|
|
+import com.ruoyi.framework.web.page.TableDataInfo;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 生产记录Controller
|
|
|
+ *
|
|
|
+ * @author ssy
|
|
|
+ * @date 2024-10-08
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/production/prdRecord")
|
|
|
+public class TPrdRecordController extends BaseController
|
|
|
+{
|
|
|
+ @Autowired
|
|
|
+ private ITPrdRecordService tPrdRecordService;
|
|
|
+ @Autowired
|
|
|
+ private ITMtdDailyService tMtdDailyService;
|
|
|
+ @Resource
|
|
|
+ private TMtdItemMapper tMtdItemMapper;
|
|
|
+ @Resource
|
|
|
+ private TPrdRecordMapper tPrdRecordMapper;
|
|
|
+ @Resource
|
|
|
+ private TPrdRecordItemMapper tPrdRecordItemMapper;
|
|
|
+ /**
|
|
|
+ * 查询生产记录列表
|
|
|
+ */
|
|
|
+ @PreAuthorize("@ss.hasPermi('production:prdRecord:list')")
|
|
|
+ @GetMapping("/list")
|
|
|
+ public TableDataInfo list(TPrdRecord tPrdRecord)
|
|
|
+ {
|
|
|
+ startPage();
|
|
|
+ List<TPrdRecord> list = tPrdRecordService.selectTPrdRecordList(tPrdRecord);
|
|
|
+ for (TPrdRecord r: list
|
|
|
+ ) {
|
|
|
+ TPrdRecordItem query = new TPrdRecordItem();
|
|
|
+ query.setDailyId(r.getId());
|
|
|
+ r.setContent("");
|
|
|
+ List<TPrdRecordItem> items = tPrdRecordItemMapper.selectTPrdRecordItemList(query);
|
|
|
+ int code = 1;
|
|
|
+ for (TPrdRecordItem i :items
|
|
|
+ ) {
|
|
|
+ r.setContent(r.getContent() + code + "、" + i.getDescription() + "\n");
|
|
|
+ code++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return getDataTable(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出生产记录列表
|
|
|
+ */
|
|
|
+ @PreAuthorize("@ss.hasPermi('production:prdRecord:export')")
|
|
|
+ @Log(title = "生产记录", businessType = BusinessType.EXPORT)
|
|
|
+ @GetMapping("/export")
|
|
|
+ public AjaxResult export(TPrdRecord param)
|
|
|
+ {
|
|
|
+ TPrdRecord tPrdRecord = tPrdRecordService.selectTPrdRecordById(param.getId());
|
|
|
+ TPrdRecordItem query = new TPrdRecordItem();
|
|
|
+ query.setDailyId(param.getId());
|
|
|
+ List<TPrdRecordItem> items = tPrdRecordItemMapper.selectTPrdRecordItemList(query);
|
|
|
+ // 创建一个 Word 文档
|
|
|
+ XWPFDocument document = new XWPFDocument();
|
|
|
+ try {
|
|
|
+ // 创建输出文件的路径
|
|
|
+ FileOutputStream out = null;
|
|
|
+ // 添加每日的记录
|
|
|
+ addDayContent(document, tPrdRecord.getRecordDate(), items);
|
|
|
+ // 将内容写入文件
|
|
|
+ out = new FileOutputStream(ExcelUtil.getAbsoluteFile("daily_report.docx"));
|
|
|
+ document.write(out);
|
|
|
+ out.close();
|
|
|
+ System.out.println("Word 文档生成成功!");
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return AjaxResult.success("daily_report.docx");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加每日的内容
|
|
|
+ private static void addDayContent(XWPFDocument document, Date date, List<TPrdRecordItem> items) {
|
|
|
+ // 添加日期为标题
|
|
|
+ XWPFParagraph dateParagraph = document.createParagraph();
|
|
|
+ XWPFRun dateRun = dateParagraph.createRun();
|
|
|
+ dateRun.setBold(true);
|
|
|
+ String pattern = "yyyy年MM月dd日"; // 定义日期格式化模板
|
|
|
+
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat(pattern); // 创建日期格式化器
|
|
|
+
|
|
|
+ String formattedDate = dateFormat.format(date); // 将日期转换为字符串
|
|
|
+ dateRun.setText(formattedDate);
|
|
|
+ dateRun.addCarriageReturn();
|
|
|
+
|
|
|
+ // 添加条目列表
|
|
|
+ for (int i = 0; i < items.size(); i++) {
|
|
|
+ XWPFParagraph itemParagraph = document.createParagraph();
|
|
|
+ XWPFRun itemRun = itemParagraph.createRun();
|
|
|
+ itemRun.setText((i + 1) + "、\t" + items.get(i).getDescription());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void syncMeeting(long meetingId){
|
|
|
+ TMtdDaily tMtdDaily = tMtdDailyService.selectTMtdDailyById(meetingId);
|
|
|
+ if (tMtdDaily != null) {
|
|
|
+ TPrdRecord del = new TPrdRecord();
|
|
|
+ del.setRecordDate(tMtdDaily.getMeetingDate());
|
|
|
+ tPrdRecordMapper.deleteTPrdRecordByDate(del);
|
|
|
+ }
|
|
|
+ // 插入主表
|
|
|
+ TPrdRecord record = new TPrdRecord();
|
|
|
+ record.setRecordDate(tMtdDaily.getMeetingDate());
|
|
|
+ tPrdRecordMapper.insertTPrdRecord(record);
|
|
|
+ List<TPrdRecordItem> tPrdRecordItemList = new ArrayList<>();
|
|
|
+
|
|
|
+ TPrdRecordItem recordItem1= new TPrdRecordItem();
|
|
|
+ recordItem1.setDailyId(record.getId());
|
|
|
+ recordItem1.setDescription("裂解炉运行模式" + tMtdDaily.getOptMode());
|
|
|
+ tPrdRecordItemList.add(recordItem1);
|
|
|
+
|
|
|
+ TPrdRecordItem recordItem2= new TPrdRecordItem();
|
|
|
+ recordItem2.setDescription("负荷:裂解:" + tMtdDaily.getSplit()+ " AEU:" + tMtdDaily.getAeu() + " PGU:" + tMtdDaily.getPgu());
|
|
|
+ recordItem2.setDailyId(record.getId());
|
|
|
+ tPrdRecordItemList.add(recordItem2);
|
|
|
+
|
|
|
+ //获取item列表
|
|
|
+ TMtdItem item = new TMtdItem();
|
|
|
+ item.setDailyId(meetingId);
|
|
|
+ item.setItemType(0);
|
|
|
+ List<TMtdItem> item0 = tMtdItemMapper.selectTMtdItemList(item);
|
|
|
+
|
|
|
+ item.setItemType(1);
|
|
|
+ List<TMtdItem> item1 = tMtdItemMapper.selectTMtdItemList(item);
|
|
|
+ item0.addAll(item1);
|
|
|
+
|
|
|
+ item.setItemType(2);
|
|
|
+ List<TMtdItem> item2 = tMtdItemMapper.selectTMtdItemList(item);
|
|
|
+ item0.addAll(item2);
|
|
|
+
|
|
|
+ item.setItemType(3);
|
|
|
+ List<TMtdItem> item3 = tMtdItemMapper.selectTMtdItemList(item);
|
|
|
+ item0.addAll(item3);
|
|
|
+
|
|
|
+ for (TMtdItem i: item0
|
|
|
+ ) {
|
|
|
+ TPrdRecordItem recordItem= new TPrdRecordItem();
|
|
|
+ recordItem.setItem(i.getItem());
|
|
|
+ recordItem.setDailyId(record.getId());
|
|
|
+ recordItem.setDescription(i.getDescription());
|
|
|
+ tPrdRecordItemList.add(recordItem);
|
|
|
+ }
|
|
|
+ for (TPrdRecordItem i : tPrdRecordItemList
|
|
|
+ ) {
|
|
|
+ tPrdRecordItemMapper.insertTPrdRecordItem(i);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取生产记录详细信息
|
|
|
+ */
|
|
|
+ @PreAuthorize("@ss.hasPermi('production:prdRecord:query')")
|
|
|
+ @GetMapping(value = "/{id}")
|
|
|
+ public AjaxResult getInfo(@PathVariable("id") Long id)
|
|
|
+ {
|
|
|
+ TPrdRecord tPrdRecord = tPrdRecordService.selectTPrdRecordById(id);
|
|
|
+ TPrdRecordItem query = new TPrdRecordItem();
|
|
|
+ query.setDailyId(tPrdRecord.getId());
|
|
|
+ List<TPrdRecordItem> items = tPrdRecordItemMapper.selectTPrdRecordItemList(query);
|
|
|
+
|
|
|
+ tPrdRecord.setItems(items);
|
|
|
+ return AjaxResult.success(tPrdRecord);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增生产记录
|
|
|
+ */
|
|
|
+ @PreAuthorize("@ss.hasPermi('production:prdRecord:add')")
|
|
|
+ @Log(title = "生产记录", businessType = BusinessType.INSERT)
|
|
|
+ @PostMapping
|
|
|
+ public AjaxResult add(@RequestBody TPrdRecord tPrdRecord)
|
|
|
+ {
|
|
|
+ return toAjax(tPrdRecordService.insertTPrdRecord(tPrdRecord));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改生产记录
|
|
|
+ */
|
|
|
+ @PreAuthorize("@ss.hasPermi('production:prdRecord:edit')")
|
|
|
+ @Log(title = "生产记录", businessType = BusinessType.UPDATE)
|
|
|
+ @PutMapping
|
|
|
+ public AjaxResult edit(@RequestBody TPrdRecord tPrdRecord)
|
|
|
+ {
|
|
|
+ logger.info(JSON.toJSONString(tPrdRecord));
|
|
|
+ return toAjax(tPrdRecordService.updateTPrdRecord(tPrdRecord));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除生产记录
|
|
|
+ */
|
|
|
+ @PreAuthorize("@ss.hasPermi('production:prdRecord:remove')")
|
|
|
+ @Log(title = "生产记录", businessType = BusinessType.DELETE)
|
|
|
+ @DeleteMapping("/{ids}")
|
|
|
+ public AjaxResult remove(@PathVariable Long[] ids)
|
|
|
+ {
|
|
|
+ return toAjax(tPrdRecordService.deleteTPrdRecordByIds(ids));
|
|
|
+ }
|
|
|
+}
|