Parcourir la source

ly 生产记录

ly il y a 8 mois
Parent
commit
a57379996e

+ 57 - 3
master/src/main/java/com/ruoyi/project/production/controller/TPrdRecordController.java

@@ -114,6 +114,42 @@ public class TPrdRecordController extends BaseController
         }
         return AjaxResult.success("daily_report.docx");
     }
+    /**
+     * 导出生产记录列表
+     */
+    @PreAuthorize("@ss.hasPermi('production:prdRecord:export')")
+    @Log(title = "生产记录", businessType = BusinessType.EXPORT)
+    @GetMapping("/exportMonth")
+    public AjaxResult exportMonth(TPrdRecord param)
+    {
+        List<TPrdRecord> list = tPrdRecordService.selectTPrdRecordList(param);
+        // 创建一个 Word 文档
+        XWPFDocument document = new XWPFDocument();
+        try {
+            // 创建输出文件的路径
+            FileOutputStream out = null;
+            for (TPrdRecord t: list
+                 ) {
+                TPrdRecordItem query = new TPrdRecordItem();
+                query.setDailyId(t.getId());
+                List<TPrdRecordItem> items = tPrdRecordItemMapper.selectTPrdRecordItemList(query);
+                // 添加每日的记录
+                addDayContent(document, t.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) {
@@ -127,7 +163,7 @@ public class TPrdRecordController extends BaseController
 
         String formattedDate = dateFormat.format(date); // 将日期转换为字符串
         dateRun.setText(formattedDate);
-        dateRun.addCarriageReturn();
+
 
         // 添加条目列表
         for (int i = 0; i < items.size(); i++) {
@@ -135,6 +171,10 @@ public class TPrdRecordController extends BaseController
             XWPFRun itemRun = itemParagraph.createRun();
             itemRun.setText((i + 1) + "、\t" + items.get(i).getDescription());
         }
+        // 添加空白
+        XWPFParagraph dateParagraph2 = document.createParagraph();
+        XWPFRun dateRun2 = dateParagraph2.createRun();
+        dateRun2.addCarriageReturn();
     }
 
     public void syncMeeting(long meetingId){
@@ -217,7 +257,14 @@ public class TPrdRecordController extends BaseController
     @PostMapping
     public AjaxResult add(@RequestBody TPrdRecord tPrdRecord)
     {
-        return toAjax(tPrdRecordService.insertTPrdRecord(tPrdRecord));
+        logger.info(JSON.toJSONString(tPrdRecord));
+        tPrdRecordService.insertTPrdRecord(tPrdRecord);
+        for (TPrdRecordItem i : tPrdRecord.getItems()
+        ) {
+            i.setDailyId(tPrdRecord.getId());
+            tPrdRecordItemMapper.insertTPrdRecordItem(i);
+        }
+        return toAjax(1);
     }
 
     /**
@@ -229,7 +276,14 @@ public class TPrdRecordController extends BaseController
     public AjaxResult edit(@RequestBody TPrdRecord tPrdRecord)
     {
         logger.info(JSON.toJSONString(tPrdRecord));
-        return toAjax(tPrdRecordService.updateTPrdRecord(tPrdRecord));
+        tPrdRecordService.updateTPrdRecord(tPrdRecord);
+        tPrdRecordItemMapper.deleteTPrdRecordItemByRecordId(tPrdRecord.getId());
+        for (TPrdRecordItem i : tPrdRecord.getItems()
+        ) {
+            i.setDailyId(tPrdRecord.getId());
+            tPrdRecordItemMapper.insertTPrdRecordItem(i);
+        }
+        return toAjax(1);
     }
 
     /**

+ 9 - 0
master/src/main/java/com/ruoyi/project/production/domain/TPrdRecord.java

@@ -31,6 +31,7 @@ public class TPrdRecord extends BaseEntity
     @Excel(name = "记录时间", width = 30, dateFormat = "yyyy-MM-dd")
     private Date recordDate;
 
+    private Date recordMonth;
     /** 删除 */
     private Long delFlag;
 
@@ -180,6 +181,14 @@ public class TPrdRecord extends BaseEntity
         this.content = content;
     }
 
+    public Date getRecordMonth() {
+        return recordMonth;
+    }
+
+    public void setRecordMonth(Date recordMonth) {
+        this.recordMonth = recordMonth;
+    }
+
     @Override
     public String toString() {
         return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)

+ 2 - 0
master/src/main/java/com/ruoyi/project/production/mapper/TPrdRecordItemMapper.java

@@ -60,4 +60,6 @@ public interface TPrdRecordItemMapper
      * @return 结果
      */
     public int deleteTPrdRecordItemByIds(Long[] ids);
+
+    void deleteTPrdRecordItemByRecordId(Long id);
 }

+ 0 - 1
master/src/main/java/com/ruoyi/project/production/mapper/TPrdRecordMapper.java

@@ -27,7 +27,6 @@ public interface TPrdRecordMapper
      * @param tPrdRecord 生产记录
      * @return 生产记录集合
      */
-    @DataScope(deptAlias = "d")
     public List<TPrdRecord> selectTPrdRecordList(TPrdRecord tPrdRecord);
 
     /**

+ 5 - 0
master/src/main/resources/mybatis/production/TPrdRecordItemMapper.xml

@@ -105,6 +105,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         update t_prd_record_item set del_flag = 2 where id = #{id}
     </update>
 
+    <update id="deleteTPrdRecordItemByRecordId" parameterType="Long">
+        update t_prd_record_item set del_flag = 2 where daily_id = #{id}
+    </update>
+
+
     <update id="deleteTPrdRecordItemByIds" parameterType="String">
         update t_prd_record_item set del_flag = 2 where id in
         <foreach item="id" collection="array" open="(" separator="," close=")">

+ 2 - 0
master/src/main/resources/mybatis/production/TPrdRecordMapper.xml

@@ -28,6 +28,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <where>
             <if test="recorder != null  and recorder != ''"> and recorder = #{recorder}</if>
             <if test="recordDate != null "> and record_date = #{recordDate}</if>
+            <if test="recordMonth != null "> and  TO_CHAR(record_date, 'YYYY-MM') = TO_CHAR(#{recordMonth}, 'YYYY-MM') </if>
+
             <if test="createrCode != null  and createrCode != ''"> and creater_code = #{createrCode}</if>
             <if test="createdate != null "> and createdate = #{createdate}</if>
             <if test="updaterCode != null  and updaterCode != ''"> and updater_code = #{updaterCode}</if>

+ 10 - 0
ui/src/api/production/prdRecord.js

@@ -51,3 +51,13 @@ export function exportPrdRecord(query) {
     params: query
   })
 }
+
+// 导出生产记录
+export function exportPrdRecordMonth(query) {
+  return request({
+    url: '/production/prdRecord/exportMonth',
+    method: 'get',
+    params: query
+  })
+}
+

+ 36 - 35
ui/src/views/production/prdRecord/index.vue

@@ -2,24 +2,15 @@
   <div class="app-container">
     <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
 
-      <el-form-item label="记录时间" prop="recordDate">
+      <el-form-item label="月份" prop="recordMonth">
         <el-date-picker clearable size="small" style="width: 200px"
-          v-model="queryParams.recordDate"
-          type="date"
+          v-model="queryParams.recordMonth"
+          type="month"
           value-format="yyyy-MM-dd"
-          placeholder="选择记录时间">
+          @change="handleQuery"
+          placeholder="选择月份">
         </el-date-picker>
       </el-form-item>
-
-      <el-form-item label="备注" prop="remarks">
-        <el-input
-          v-model="queryParams.remarks"
-          placeholder="请输入备注"
-          clearable
-          size="small"
-          @keyup.enter.native="handleQuery"
-        />
-      </el-form-item>
       <el-form-item>
         <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
         <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
@@ -56,23 +47,15 @@
           v-hasPermi="['production:prdRecord:remove']"
         >删除</el-button>
       </el-col>
-        <el-col :span="1.5">
-            <el-button
-                    type="info"
-                    icon="el-icon-upload2"
-                    size="mini"
-                    @click="handleImport"
-                    v-hasPermi="['production:prdRecord:edit']"
-            >导入</el-button>
-        </el-col>
       <el-col :span="1.5">
         <el-button
           type="warning"
           icon="el-icon-download"
           size="mini"
-          @click="handleExport"
+          :disabled="monthChoose"
+          @click="handleExportMonth"
           v-hasPermi="['production:prdRecord:export']"
-        >导出</el-button>
+        >按月导出</el-button>
       </el-col>
 	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
     </el-row>
@@ -84,8 +67,8 @@
           <span>{{ parseTime(scope.row.recordDate, '{y}-{m}-{d}') }}</span>
         </template>
       </el-table-column>
-      <el-table-column label="记录人" align="center" prop="recorder" :show-overflow-tooltip="true"/>
-      <el-table-column label="内容" align="center" prop="content" width="720" >
+<!--      <el-table-column label="记录人" align="center" prop="recorder" :show-overflow-tooltip="true"/>-->
+      <el-table-column label="内容" align="center" prop="content"  >
         <template slot-scope="scope">
           <span style="white-space: pre-line;">{{ scope.row.content }}</span>
         </template>
@@ -93,8 +76,8 @@
 
 
 
-      <el-table-column label="备注" align="center" prop="remarks" :show-overflow-tooltip="true"/>
-      <el-table-column label="操作" align="center" fixed="right" width="120" class-name="small-padding fixed-width">
+      <el-table-column label="备注" align="center" prop="remarks"  width="400" />
+      <el-table-column label="操作" align="center" fixed="right" width="160" class-name="small-padding fixed-width">
         <template slot-scope="scope">
           <el-button
             size="mini"
@@ -199,7 +182,7 @@
 </template>
 
 <script>
-import { listPrdRecord, getPrdRecord, delPrdRecord, addPrdRecord, updatePrdRecord, exportPrdRecord, importTemplate} from "@/api/production/prdRecord";
+import { exportPrdRecordMonth,listPrdRecord, getPrdRecord, delPrdRecord, addPrdRecord, updatePrdRecord, exportPrdRecord, importTemplate} from "@/api/production/prdRecord";
 import { treeselect } from "@/api/system/dept";
 import { getToken } from "@/utils/auth";
 import Treeselect from "@riophae/vue-treeselect";
@@ -218,8 +201,9 @@ export default {
       single: true,
       // 非多个禁用
       multiple: true,
+      monthChoose: true,
       // 显示搜索条件
-      showSearch: false,
+      showSearch: true,
       // 总条数
       total: 0,
       // 生产记录表格数据
@@ -249,7 +233,7 @@ export default {
       // 查询参数
       queryParams: {
         pageNum: 1,
-        pageSize: 20,
+        pageSize: 30,
         recorder: null,
         recordDate: null,
         createrCode: null,
@@ -257,7 +241,8 @@ export default {
         updaterCode: null,
         updatedate: null,
         deptId: null,
-        remarks: null
+        remarks: null,
+        recordMonth: null,
       },
       // 表单参数
       form: {},
@@ -313,13 +298,15 @@ export default {
         updaterCode: null,
         updatedate: null,
         deptId: null,
-        remarks: null
+        remarks: null,
+        items:[],
       };
       this.resetForm("form");
     },
     /** 搜索按钮操作 */
     handleQuery() {
       this.queryParams.pageNum = 1;
+      this.monthChoose = !this.queryParams.recordMonth
       this.getList();
     },
     /** 重置按钮操作 */
@@ -338,6 +325,7 @@ export default {
       this.reset();
       this.open = true;
       this.title = "添加生产记录";
+      this.form.items.push({description: ''})
     },
     /** 修改按钮操作 */
     handleUpdate(row) {
@@ -386,7 +374,7 @@ export default {
     /** 导出按钮操作 */
     handleExport(row) {
       let param = {id:row.id}
-      this.$confirm('是否确认导出所有生产记录数据项?', "警告", {
+      this.$confirm('是否确认导出本条生产记录数据项?', "警告", {
           confirmButtonText: "确定",
           cancelButtonText: "取消",
           type: "warning"
@@ -395,6 +383,19 @@ export default {
         }).then(response => {
           this.download(response.msg);
         })
+    },
+    /** 导出按钮操作 */
+    handleExportMonth(row) {
+      const queryParams = this.queryParams;
+      this.$confirm('是否确认导出生产记录数据项?', "警告", {
+        confirmButtonText: "确定",
+        cancelButtonText: "取消",
+        type: "warning"
+      }).then(function() {
+        return exportPrdRecordMonth(queryParams);
+      }).then(response => {
+        this.download(response.msg);
+      })
     },
       /** 导入按钮操作 */
       handleImport() {