javaweb-plus/javaweb-cms/src/main/java/com/javaweb/geo/controller/TubLogController.java
@@ -1,15 +1,13 @@ package com.javaweb.geo.controller; import java.util.List; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.util.ObjectUtils; import org.springframework.web.bind.annotation.*; import com.javaweb.common.annotation.Log; import com.javaweb.common.enums.BusinessType; import com.javaweb.geo.domain.TubLog; @@ -18,17 +16,17 @@ import com.javaweb.common.core.domain.AjaxResult; import com.javaweb.common.utils.poi.ExcelUtil; import com.javaweb.common.core.page.TableDataInfo; import org.springframework.web.multipart.MultipartFile; /** * 材料出入库记录Controller * * * @author cxy * @date 2024-05-22 */ @Controller @RequestMapping("/geo/TubLog") public class TubLogController extends BaseController { public class TubLogController extends BaseController { private String prefix = "geo/TubLog"; @Autowired @@ -36,8 +34,8 @@ @RequiresPermissions("geo:TubLog:view") @GetMapping() public String TubLog() { public String TubLog(String id, ModelMap mmap) { mmap.put("projectId", id); return prefix + "/TubLog"; } @@ -47,8 +45,7 @@ @RequiresPermissions("geo:TubLog:list") @PostMapping("/list") @ResponseBody public TableDataInfo list(TubLog tubLog) { public TableDataInfo list(TubLog tubLog) { startPage(); List<TubLog> list = tubLogService.selectTubLogList(tubLog); return getDataTable(list); @@ -61,8 +58,7 @@ @Log(title = "材料出入库记录", businessType = BusinessType.EXPORT) @PostMapping("/export") @ResponseBody public AjaxResult export(TubLog tubLog) { public AjaxResult export(TubLog tubLog) { List<TubLog> list = tubLogService.selectTubLogList(tubLog); ExcelUtil<TubLog> util = new ExcelUtil<TubLog>(TubLog.class); return util.exportExcel(list, "TubLog"); @@ -72,8 +68,17 @@ * 新增材料出入库记录 */ @GetMapping("/add") public String add() { public String add(String projectId, ModelMap mmap) { Integer number = tubLogService.selectMaxTubLogId(projectId); if (ObjectUtils.isEmpty(number)){ number = 1; }else { number++; } String formattedNumber = String.format("%06d", number); String code = "ZTCJ" + formattedNumber; mmap.put("projectId", projectId); mmap.put("code", code); return prefix + "/add"; } @@ -84,8 +89,7 @@ @Log(title = "材料出入库记录", businessType = BusinessType.INSERT) @PostMapping("/add") @ResponseBody public AjaxResult addSave(TubLog tubLog) { public AjaxResult addSave(TubLog tubLog) { return toAjax(tubLogService.insertTubLog(tubLog)); } @@ -93,8 +97,7 @@ * 修改材料出入库记录 */ @GetMapping("/edit/{id}") public String edit(@PathVariable("id") Integer id, ModelMap mmap) { public String edit(@PathVariable("id") Integer id, ModelMap mmap) { TubLog tubLog = tubLogService.selectTubLogById(id); mmap.put("tubLog", tubLog); return prefix + "/edit"; @@ -107,8 +110,7 @@ @Log(title = "材料出入库记录", businessType = BusinessType.UPDATE) @PostMapping("/edit") @ResponseBody public AjaxResult editSave(TubLog tubLog) { public AjaxResult editSave(TubLog tubLog) { return toAjax(tubLogService.updateTubLog(tubLog)); } @@ -117,10 +119,21 @@ */ @RequiresPermissions("geo:TubLog:remove") @Log(title = "材料出入库记录", businessType = BusinessType.DELETE) @PostMapping( "/remove") @PostMapping("/remove") @ResponseBody public AjaxResult remove(String ids) { public AjaxResult remove(String ids) { return toAjax(tubLogService.deleteTubLogByIds(ids)); } /** * 导入管材出入库记录 */ @RequiresPermissions("geo:deviceLog:import") @Log(title = "导入管材出入库记录") @PostMapping( "/importTubLog/{projectId}") @ResponseBody public AjaxResult importTubLog(@PathVariable("projectId") String projectId, @RequestParam("file") MultipartFile file, boolean updateSupport){ String message = tubLogService.importTubLog(projectId,file,updateSupport); return AjaxResult.success(message); } } javaweb-plus/javaweb-cms/src/main/java/com/javaweb/geo/mapper/TubLogMapper.java
@@ -1,6 +1,8 @@ package com.javaweb.geo.mapper; import com.javaweb.geo.domain.TubLog; import org.apache.ibatis.annotations.Param; import java.util.List; /** @@ -58,4 +60,10 @@ * @return 结果 */ public int deleteTubLogByIds(String[] ids); /** * 查询数据库中id最大值 * @return */ Integer selectMaxTubLogId(@Param("projectId") String projectId); } javaweb-plus/javaweb-cms/src/main/java/com/javaweb/geo/service/ITubLogService.java
@@ -1,6 +1,8 @@ package com.javaweb.geo.service; import com.javaweb.geo.domain.TubLog; import org.springframework.web.multipart.MultipartFile; import java.util.List; /** @@ -58,4 +60,15 @@ * @return 结果 */ public int deleteTubLogById(Integer id); /** * 查询数据库中id最大值 * @return */ Integer selectMaxTubLogId(String projectId); /** * 导入管材出入库记录 */ String importTubLog(String projectId, MultipartFile file, boolean updateSupport); } javaweb-plus/javaweb-cms/src/main/java/com/javaweb/geo/service/impl/DeviceLogServiceImpl.java
@@ -176,7 +176,6 @@ private List<DeviceLog> readData(String filepath) { ExcelReader reader = ExcelUtil.getReader(filepath, 0); reader.addHeaderAlias("设备名称", "deviceName"); reader.addHeaderAlias("类型", "type"); reader.addHeaderAlias("入库时间", "inboundDate"); reader.addHeaderAlias("出库时间", "outboundDate"); reader.addHeaderAlias("经办人", "optUser"); javaweb-plus/javaweb-cms/src/main/java/com/javaweb/geo/service/impl/TubLogServiceImpl.java
@@ -1,14 +1,20 @@ package com.javaweb.geo.service.impl; import java.io.File; import java.util.List; import cn.hutool.poi.excel.ExcelReader; import cn.hutool.poi.excel.ExcelUtil; import com.javaweb.common.config.Global; import com.javaweb.common.utils.DateUtils; import com.javaweb.geo.domain.TubLog; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.javaweb.geo.mapper.TubLogMapper; import com.javaweb.geo.domain.TubLog; import com.javaweb.geo.service.ITubLogService; import com.javaweb.common.core.text.Convert; import org.springframework.util.ObjectUtils; import org.springframework.web.multipart.MultipartFile; /** * 材料出入库记录Service业务层处理 @@ -18,8 +24,11 @@ */ @Service public class TubLogServiceImpl implements ITubLogService { @Autowired private TubLogMapper tubLogMapper; private String fileSaveDir = Global.getProfile() + "\\template\\" ; /** * 查询材料出入库记录 @@ -87,4 +96,78 @@ public int deleteTubLogById(Integer id) { return tubLogMapper.deleteTubLogById(id); } /** * 查询数据库中id最大值 * @return */ @Override public Integer selectMaxTubLogId(String projectId) { return tubLogMapper.selectMaxTubLogId(projectId); } /** * 导入管材出入库记录 */ @Override public String importTubLog(String projectId, MultipartFile file, boolean updateSupport) { // 关联code Integer number = tubLogMapper.selectMaxTubLogId(projectId); try { String dest = saveExcel(file); List<TubLog> list = readData(dest); for (TubLog item : list) { // 转换项目信息 item.setProjectId(projectId); // 转换number信息 if (ObjectUtils.isEmpty(number)){ number = 1; }else { number++; } String code = "ZTCJ" + String.format("%06d", number); item.setCode(code); item.setCreateDate(DateUtils.getNowDate()); insertTubLog(item); } } catch (Exception e) { return e.toString(); } return "导入完毕" ; } private String saveExcel(MultipartFile file) { String filename = file.getOriginalFilename(); File dir = new File(fileSaveDir); if (!dir.exists()) { dir.mkdir(); } String addr = fileSaveDir + filename; try { File dest = new File(addr); file.transferTo(dest); } catch (Exception e) { return null; } return addr; } private List<TubLog> readData(String filepath) { ExcelReader reader = ExcelUtil.getReader(filepath, 0); reader.addHeaderAlias("管材名称", "tubName"); reader.addHeaderAlias("入库时间", "inboundDate"); reader.addHeaderAlias("出库时间", "outboundDate"); reader.addHeaderAlias("经办人", "optUser"); reader.addHeaderAlias("负责人", "applyUser"); reader.addHeaderAlias("出入库数量", "number"); reader.addHeaderAlias("数据单位", "unit"); reader.addHeaderAlias("备注", "remark"); List<TubLog> list = reader.readAll(TubLog.class); return list; } } javaweb-plus/javaweb-cms/src/main/resources/mapper/geo/TubLogMapper.xml
@@ -45,7 +45,11 @@ <include refid="selectTubLogVo"/> where id = #{id} </select> <select id="selectMaxTubLogId" resultType="java.lang.Integer"> SELECT MAX(id) FROM js_tub_log where project_id = #{projectId} </select> <insert id="insertTubLog" parameterType="TubLog" useGeneratedKeys="true" keyProperty="id"> insert into js_tub_log <trim prefix="(" suffix=")" suffixOverrides=","> javaweb-plus/javaweb-cms/src/main/resources/templates/geo/TubLog/TubLog.html
@@ -41,9 +41,12 @@ <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="geo:TubLog:remove"> <i class="fa fa-remove"></i> 删除 </a> <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="geo:TubLog:export"> <i class="fa fa-download"></i> 导出 </a> <!-- <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="geo:TubLog:export">--> <!-- <i class="fa fa-download"></i> 导出--> <!-- </a>--> <a class="btn btn-info" onclick="$.table.importExcel()" shiro:hasPermission="geo:TubLog:import"> <i class="fa fa-upload"></i> 导入 </a> </div> <div class="col-sm-12 select-table table-striped"> <table id="bootstrap-table"></table> @@ -55,14 +58,16 @@ var editFlag = [[${@permission.hasPermi('geo:TubLog:edit')}]]; var removeFlag = [[${@permission.hasPermi('geo:TubLog:remove')}]]; var prefix = ctx + "geo/TubLog"; var projectId=[[${projectId}]]; $(function() { var options = { url: prefix + "/list", createUrl: prefix + "/add", url: prefix + "/list?projectId="+projectId, createUrl: prefix + "/add?projectId="+projectId, updateUrl: prefix + "/edit/{id}", removeUrl: prefix + "/remove", exportUrl: prefix + "/export", importUrl: prefix + "/importTubLog/"+projectId, modalName: "材料出入库记录", columns: [{ checkbox: true @@ -79,10 +84,6 @@ { field : 'tubName', title : '管材名称' }, { field : 'type', title : '类型' }, { field : 'outboundDate', @@ -109,10 +110,6 @@ title : '数据单位' }, { field : 'createDate', title : '时间' }, { field : 'remark', title : '备注' }, @@ -129,6 +126,31 @@ }; $.table.init(options); }); //下载 function importTemplate() { var filename="管材出入库记录模板.xls"; window.location.href = ctx + "common/download?fileName=" + encodeURI(filename) + "&delete=" + false; } </script> </body> <!-- 导入区域 --> <script id="importTpl" type="text/template"> <form enctype="multipart/form-data" class="mt20 mb10"> <div class="col-xs-offset-1"> <input type="file" id="file" name="file"/> <div class="mt10 pt5"> <input type="checkbox" id="updateSupport" name="updateSupport" title="导入设备出入库信息"> 是否更新已经存在的数据 <a onclick="importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a> </div> <font color="red" class="pull-left mt10"> 提示:仅允许导入“xls”或“xlsx”格式文件! </font> </div> </form> </script> </html> javaweb-plus/javaweb-cms/src/main/resources/templates/geo/TubLog/add.html
@@ -10,7 +10,7 @@ <div class="form-group"> <label class="col-sm-3 control-label">出入库单子号:</label> <div class="col-sm-8"> <input name="code" class="form-control" type="text"> <input name="code" th:value="${code}" class="form-control" type="text" disabled="disabled"> </div> </div> <div class="form-group"> @@ -19,15 +19,15 @@ <input name="tubName" class="form-control" type="text"> </div> </div> <div class="form-group"> <label class="col-sm-3 control-label">类型:</label> <div class="col-sm-8"> <select name="type" class="form-control m-b"> <option value="">所有</option> </select> <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 代码生成请选择字典属性</span> </div> </div> <!-- <div class="form-group"> --> <!-- <label class="col-sm-3 control-label">类型:</label>--> <!-- <div class="col-sm-8">--> <!-- <select name="type" class="form-control m-b">--> <!-- <option value="">所有</option>--> <!-- </select>--> <!-- <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 代码生成请选择字典属性</span>--> <!-- </div>--> <!-- </div>--> <div class="form-group"> <label class="col-sm-3 control-label">出库时间:</label> <div class="col-sm-8"> @@ -70,28 +70,31 @@ <input name="unit" class="form-control" type="text"> </div> </div> <div class="form-group"> <label class="col-sm-3 control-label">时间:</label> <div class="form-group"> <label class="col-sm-3 control-label">备注:</label> <div class="col-sm-8"> <div class="input-group date"> <span class="input-group-addon"><i class="fa fa-calendar"></i></span> <input name="createDate" class="form-control" placeholder="yyyy-MM-dd" type="text"> </div> <textarea id="remark" name="remark" class="form-control"></textarea> </div> </div> </form> </div> <th:block th:include="include :: footer" /> <th:block th:include="include :: datetimepicker-js" /> <script type="text/javascript"> <script th:inline="javascript"> var prefix = ctx + "geo/TubLog" var projectId = [[${projectId}]]; var code = [[${code}]]; $("#form-TubLog-add").validate({ focusCleanup: true }); function submitHandler() { if ($.validate.form()) { $.operate.save(prefix + "/add", $('#form-TubLog-add').serialize()); let formData = $('#form-TubLog-add').serialize(); let data = formData + "&projectId=" + projectId + "&code=" + code; $.operate.save(prefix + "/add", data); } } @@ -102,12 +105,6 @@ }); $("input[name='inboundDate']").datetimepicker({ format: "yyyy-mm-dd", minView: "month", autoclose: true }); $("input[name='createDate']").datetimepicker({ format: "yyyy-mm-dd", minView: "month", autoclose: true javaweb-plus/javaweb-cms/src/main/resources/templates/geo/TubLog/edit.html
@@ -11,7 +11,7 @@ <div class="form-group"> <label class="col-sm-3 control-label">出入库单子号:</label> <div class="col-sm-8"> <input name="code" th:field="*{code}" class="form-control" type="text"> <input name="code" th:field="*{code}" class="form-control" type="text" disabled="disabled"> </div> </div> <div class="form-group"> @@ -20,15 +20,15 @@ <input name="tubName" th:field="*{tubName}" class="form-control" type="text"> </div> </div> <div class="form-group"> <label class="col-sm-3 control-label">类型:</label> <div class="col-sm-8"> <select name="type" class="form-control m-b"> <option value="">所有</option> </select> <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 代码生成请选择字典属性</span> </div> </div> <!-- <div class="form-group"> --> <!-- <label class="col-sm-3 control-label">类型:</label>--> <!-- <div class="col-sm-8">--> <!-- <select name="type" class="form-control m-b">--> <!-- <option value="">所有</option>--> <!-- </select>--> <!-- <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 代码生成请选择字典属性</span>--> <!-- </div>--> <!-- </div>--> <div class="form-group"> <label class="col-sm-3 control-label">出库时间:</label> <div class="col-sm-8"> @@ -71,21 +71,20 @@ <input name="unit" th:field="*{unit}" class="form-control" type="text"> </div> </div> <div class="form-group"> <label class="col-sm-3 control-label">时间:</label> <div class="form-group"> <label class="col-sm-3 control-label">备注:</label> <div class="col-sm-8"> <div class="input-group date"> <span class="input-group-addon"><i class="fa fa-calendar"></i></span> <input name="createDate" th:value="${#dates.format(tubLog.createDate, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text"> </div> <textarea id="remark" th:field="*{remark}" name="remark" class="form-control"></textarea> </div> </div> </form> </div> <th:block th:include="include :: footer" /> <th:block th:include="include :: datetimepicker-js" /> <script type="text/javascript"> var prefix = ctx + "geo/TubLog"; $("#form-TubLog-edit").validate({ focusCleanup: true }); @@ -103,12 +102,6 @@ }); $("input[name='inboundDate']").datetimepicker({ format: "yyyy-mm-dd", minView: "month", autoclose: true }); $("input[name='createDate']").datetimepicker({ format: "yyyy-mm-dd", minView: "month", autoclose: true javaweb-plus/javaweb-cms/src/main/resources/templates/geo/deviceLog/deviceLog.html
@@ -11,10 +11,6 @@ <div class="select-list"> <ul> <li> <p>工单号:</p> <input type="text" name="code"/> </li> <li> <p>名称:</p> <input type="text" name="deviceName"/> </li> javaweb-plus/javaweb-cms/src/main/resources/templates/geo/project/navigate.html
@@ -46,6 +46,11 @@ </div> <div class="box-header "> <div class="box-title"> <i class="glyphicon glyphicon-retweet"></i> <a class="afont" th:href="@{/geo/TubLog(id=${project.ids})}" target="mainFrame" onclick="selected(this)">材料管理</a> </div> </div> <div class="box-header "> <div class="box-title"> <i class="glyphicon glyphicon-object-align-horizontal"></i> <a class="afont" th:href="@{/geo/projectData(id=${project.ids},type='1')}" target="mainFrame" onclick="selected(this)">质量管理</a> </div> </div>