Commit fd33a7486d7b3b6b18a2c80eaa399da6ac4d5732

Authored by mahuandong
1 parent 28a1088c

添加入库质检行内编辑后台修改方法

src/main/java/com/huaheng/pc/check/checkingRegister/controller/CheckingRegisterController.java
... ... @@ -16,6 +16,7 @@ import com.huaheng.framework.web.page.PageDomain;
16 16 import com.huaheng.framework.web.page.TableDataInfo;
17 17 import com.huaheng.framework.web.page.TableSupport;
18 18 import com.huaheng.pc.check.checkHeader.domain.CheckHeader;
  19 +import com.huaheng.pc.check.checkHeader.service.CheckHeaderService;
19 20 import com.huaheng.pc.check.checkingRegister.domain.CheckingRegister;
20 21 import com.huaheng.pc.check.checkingRegister.service.CheckingRegisterService;
21 22 import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
... ... @@ -42,12 +43,20 @@ public class CheckingRegisterController extends BaseController {
42 43  
43 44 @Resource
44 45 private CheckingRegisterService checkingRegisterService;
  46 + @Resource
  47 + private CheckHeaderService checkHeaderService;
45 48  
46 49 private String prefix = "check/checkingRegister";
47 50  
48 51 @RequiresPermissions("check:checkingRegister:view")
49 52 @GetMapping("/{checkId}")
50 53 public String checkingRegister(@PathVariable("checkId") Integer checkId, ModelMap modelMap) {
  54 + if (checkId != 0){
  55 + CheckHeader checkHeader = checkHeaderService.getById(checkId);
  56 + modelMap.put("checkHeaderId",checkHeader.getId());
  57 + modelMap.put("checkCode",checkHeader.getCode());
  58 + }
  59 +
51 60 modelMap.put("checkId",checkId);
52 61 return prefix + "/checkingRegister";
53 62 }
... ... @@ -144,9 +153,7 @@ public class CheckingRegisterController extends BaseController {
144 153 @PostMapping("/edit")
145 154 @ResponseBody
146 155 public AjaxResult editSave(CheckingRegister checkingRegister) {
147   - checkingRegister.setCheckBy(ShiroUtils.getLoginName());
148   - checkingRegister.setLastUpdatedBy(ShiroUtils.getLoginName());
149   - return toAjax(checkingRegisterService.updateById(checkingRegister));
  156 + return checkingRegisterService.edit(checkingRegister);
150 157 }
151 158  
152 159 /**
... ...
src/main/java/com/huaheng/pc/check/checkingRegister/service/CheckingRegisterService.java
1 1 package com.huaheng.pc.check.checkingRegister.service;
2 2  
  3 +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4 +
  5 +import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  6 +import com.huaheng.common.exception.service.ServiceException;
  7 +import com.huaheng.common.utils.StringUtils;
  8 +import com.huaheng.common.utils.security.ShiroUtils;
  9 +import com.huaheng.framework.web.domain.AjaxResult;
  10 +import com.huaheng.pc.check.checkDetail.domain.CheckDetail;
  11 +import com.huaheng.pc.check.checkDetail.service.CheckDetailService;
  12 +import com.huaheng.pc.check.checkHeader.domain.CheckHeader;
  13 +import com.huaheng.pc.check.checkHeader.service.CheckHeaderService;
  14 +import com.huaheng.pc.config.material.domain.Material;
  15 +import com.huaheng.pc.config.material.service.MaterialService;
3 16 import org.springframework.stereotype.Service;
4 17 import javax.annotation.Resource;
  18 +import java.util.Date;
5 19 import java.util.List;
6 20 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7 21 import com.huaheng.pc.check.checkingRegister.domain.CheckingRegister;
... ... @@ -9,4 +23,65 @@ import com.huaheng.pc.check.checkingRegister.mapper.CheckingRegisterMapper;
9 23 @Service
10 24 public class CheckingRegisterService extends ServiceImpl<CheckingRegisterMapper, CheckingRegister> {
11 25  
  26 + @Resource
  27 + private CheckHeaderService checkHeaderService;
  28 + @Resource
  29 + private CheckDetailService checkDetailService;
  30 + @Resource
  31 + private MaterialService materialService;
  32 + /**
  33 + * 质检登记修改
  34 + * @return
  35 + */
  36 + public AjaxResult edit(CheckingRegister checkingRegister){
  37 +
  38 + //判断关联质检头表信息是否正确
  39 + CheckHeader checkHeader = checkHeaderService.getById(checkingRegister.getCheckHeaderId());
  40 + if (checkHeader.getEnable() == 0){
  41 + return AjaxResult.error("关联质检单无效,不允许修改");
  42 + }
  43 + //判断关联质检头表状态是否允许修改
  44 + if ("30".equals(checkHeader.getStatus())){
  45 + return AjaxResult.error("关联质检单已完成质检不允许修改质检登记");
  46 + }
  47 + //判断关联质检明细信息是否正确
  48 + LambdaQueryWrapper<CheckDetail> checkDetailLambda = Wrappers.lambdaQuery();
  49 + checkDetailLambda.eq(CheckDetail::getCheckHeaderId, checkingRegister.getCheckHeaderId());
  50 + List<CheckDetail> checkDetails = checkDetailService.list();
  51 +
  52 + int i = 0;
  53 + for (CheckDetail checkDetail: checkDetails){
  54 + if (checkDetail.getId() == checkingRegister.getReceiptDetailId()){
  55 + i = 1;
  56 + }
  57 + }
  58 + if (i == 0){
  59 + return AjaxResult.error("质检单下不存在该质检明细");
  60 + }
  61 + //判断关联质检明细物料信息是否正确
  62 + CheckDetail checkDetail = checkDetailService.getById(checkingRegister.getReceiptDetailId());
  63 + if (checkDetail.getMaterialCode() != checkingRegister.getMaterialCode()){
  64 + return AjaxResult.error("关联质检明细的物料编码不匹配");
  65 + }
  66 + LambdaQueryWrapper<Material> materialLambda = Wrappers.lambdaQuery();
  67 + materialLambda.eq(Material::getCode, checkingRegister.getMaterialCode());
  68 + Material material = materialService.getOne(materialLambda);
  69 + checkingRegister.setMaterialName(material.getName());
  70 + checkingRegister.setMaterialSpec(material.getSpec());
  71 + checkingRegister.setMaterialUnit(material.getUnit());
  72 + checkingRegister.setLastUpdatedBy(ShiroUtils.getLoginName());
  73 + checkingRegister.setCheckAt(new Date());
  74 + checkingRegister.setCheckBy(ShiroUtils.getLoginName());
  75 + if (StringUtils.isNull(checkingRegister.getId())){
  76 + checkingRegister.setCreatedBy(ShiroUtils.getLoginName());
  77 + if (!this.save(checkingRegister)){
  78 + throw new ServiceException("添加质检登记失败");
  79 + }
  80 + } else {
  81 + if (!this.updateById(checkingRegister)){
  82 + throw new SecurityException("更新质检登记失败");
  83 + }
  84 + }
  85 + return AjaxResult.success("");
  86 + }
12 87 }
... ...
src/main/resources/templates/check/checkingRegister/checkingRegister.html
... ... @@ -60,6 +60,7 @@
60 60 var editFlag = [[${@permission.hasPermi('check:checkingRegister:edit')}]];
61 61 var removeFlag = [[${@permission.hasPermi('check:checkingRegister:remove')}]];
62 62 var inventorySts = [[${@dict.getType('inventoryStatus')}]];
  63 + var curRow = {};
63 64 $(function() {
64 65  
65 66 $("#bootstrap-table").bootstrapTable({
... ... @@ -70,12 +71,14 @@
70 71 cache: false,
71 72 showToggle:true, //显示切换按钮来切换表/卡片视图。
72 73 showPaginationSwitch:true, //显示分页切换按钮
  74 + method: "post",
73 75 queryParams: queryParams,
74 76 pagination: true,
75 77 pageList: [10,25,50,100],
76 78 pageSize:10,
77 79 pageNumber:1,
78 80 uniqueId: "id",
  81 + toolbar: "#toolbar",
79 82 showRefresh: true,
80 83 minimumCountColumns: 2,
81 84 smartDisplay:true,
... ... @@ -97,7 +100,15 @@
97 100 {
98 101 field : 'checkDetailId',
99 102 title : '质检明细标识',
100   - visible : false
  103 + editable: {
  104 + type: 'text',
  105 + title: '质检明细标识',
  106 + validate: function (v) {
  107 + if (isNaN(v)) return '必须是数字';
  108 + var age = parseInt(v);
  109 + if (age < 0) return '必须是正整数';
  110 + }
  111 + }
101 112 },
102 113 {
103 114 field : 'checkHeaderId',
... ... @@ -114,15 +125,7 @@
114 125 title : '质检单号',
115 126 align:"center",
116 127 order:"asc",
117   - sortable:"true",
118   - editable: {
119   - type: 'text',
120   - title: '用户名',
121   - validate: function (v) {
122   - if (!v) return '用户名不能为空';
123   -
124   - }
125   - }
  128 + sortable:"true"
126 129 },
127 130 {
128 131 field : 'receiptDetailId',
... ... @@ -131,16 +134,7 @@
131 134 },
132 135 {
133 136 field : 'receiptCode',
134   - title : '入库单号',
135   - editable: {
136   - type: 'text',
137   - title: '入库单号',
138   - validate: function (v) {
139   - if (isNaN(v)) return '年龄必须是数字';
140   - var age = parseInt(v);
141   - if (age <= 0) return '年龄必须是正整数';
142   - }
143   - }
  137 + title : '入库单号'
144 138 },
145 139 {
146 140 field : 'referCode',
... ... @@ -158,7 +152,11 @@
158 152 },
159 153 {
160 154 field : 'materialCode',
161   - title : '物料编码'
  155 + title : '物料编码',
  156 + editable: {
  157 + type: 'text',
  158 + title: '物料编码',
  159 + }
162 160 },
163 161 {
164 162 field : 'materialName',
... ... @@ -181,13 +179,24 @@
181 179 field : 'inventorySts',
182 180 title : '库存状态',
183 181 align: 'center',
184   - formatter: function (value, row, index) {
185   - return $.table.selectDictLabel(inventorySts, value);
  182 + editable: {
  183 + type: 'select',
  184 + title: '库存状态',
  185 + source:[{value:"defective",text:"次品"},{value:"discussed",text:"待确认"},{value:"good",text:"良品"},{value:"scrap",text:"报废品"}]
186 186 }
187 187 },
188 188 {
189 189 field : 'qty',
190   - title : '数量'
  190 + title : '数量',
  191 + editable: {
  192 + type: 'text',
  193 + title: '数量',
  194 + validate: function (v) {
  195 + if (isNaN(v)) return '数量必须是数字';
  196 + var age = parseInt(v);
  197 + if (age < 0) return '数量必须是正整数';
  198 + }
  199 + }
191 200 },
192 201 {
193 202 field : 'checkBy',
... ... @@ -231,25 +240,24 @@
231 240 onClickRow: function (row, $element) {
232 241 curRow = row;
233 242 },
234   - onLoadSuccess: function (aa, bb, cc) {
235   - $("#tb_user a").editable({
236   - url: function (params) {
237   - var sName = $(this).attr("name");
238   - curRow[sName] = params.value;
239   - $.ajax({
240   - type: 'POST',
241   - url: "/Editable/Edit",
242   - data: curRow,
243   - dataType: 'JSON',
244   - success: function (data, textStatus, jqXHR) {
245   - alert('保存成功!');
246   - },
247   - error: function () { alert("error");}
248   - });
  243 + onEditableSave: function (field, row, oldValue, $el) {
  244 + $.ajax({
  245 + type: "post",
  246 + url: prefix+"/edit",
  247 + data: row,
  248 + dataType: 'JSON',
  249 + success: function (data, status) {
  250 + if (status == "success") {
  251 + alert('提交数据成功');
  252 + }
  253 + },
  254 + error: function () {
  255 + alert('编辑失败');
249 256 },
250   - type: 'text'
  257 + complete: function () {
  258 + }
251 259 });
252   - },
  260 + }
253 261 // onClickCell: function(field, value, row, $element) {
254 262 // $element.attr('contenteditable', true);
255 263 // $element.attr('bgcolor', "#FFF");
... ... @@ -261,18 +269,7 @@
261 269 // })
262 270 // },
263 271 });
264   - // $('#bootstrap-table').editable({
265   - // type: "select", //编辑框的类型。支持text|textarea|select|date|checklist等
266   - // source: [{ value: 1, text: "开发部" }, { value: 2, text: "销售部" }, {value:3,text:"行政部"}],
267   - // title: "选择部门", //编辑框的标题
268   - // disabled: false, //是否禁用编辑
269   - // mode: "popup", //编辑框的模式:支持popup和inline两种模式,默认是popup
270   - // validate: function (value) { //字段验证
271   - // if (!$.trim(value)) {
272   - // return '不能为空';
273   - // }
274   - // }
275   - // });
  272 +
276 273 // var options = {
277 274 //
278 275 // };
... ... @@ -282,6 +279,12 @@
282 279  
283 280 var checkHeaderId;
284 281  
  282 + function addButton() {
  283 + if (checkHeaderId != ""){
  284 + $("#toolbar").append("<a class=\"btn btn-outline btn-success btn-rounded\" onclick=\"addRow()\" shiro:hasPermission=\"check:checkingRegister:add\"><i class=\"fa fa-plus\"></i>新增</a>");
  285 + }
  286 + }
  287 +
285 288 function queryParams(params) {
286 289 var checkId = [[${checkId}]];
287 290 if (checkId == 0) {
... ... @@ -289,19 +292,13 @@
289 292 } else {
290 293 checkHeaderId = checkId;
291 294 }
  295 + addButton();
292 296 return {
293 297 checkHeaderId :checkHeaderId,
294 298 pageSize: params.limit,
295 299 pageNum: params.offset / params.limit + 1,
296 300 searchValue: params.search,
297 301 };
298   - addButton();
299   - }
300   -
301   - function addButton() {
302   - if (checkHeaderId != ""){
303   - $("#toolbar").append("<a class=\"btn btn-outline btn-success btn-rounded\" onclick=\"addRow()\" shiro:hasPermission=\"check:checkingRegister:add\"><i class=\"fa fa-plus\"></i>新增</a>");
304   - }
305 302 }
306 303  
307 304 function addRow() {
... ... @@ -310,9 +307,9 @@
310 307 row: {
311 308 id: '',
312 309 checkDetailId: '',
313   - checkHeaderId: '',
  310 + checkHeaderId: [[${checkHeaderId}]],
314 311 warehouseCode: '',
315   - checkCode: '',
  312 + checkCode: [[${checkCode}]],
316 313 receiptDetailId: '',
317 314 receiptCode: '',
318 315 referCode: '',
... ...
src/main/resources/templates/include.html
... ... @@ -25,6 +25,7 @@
25 25 <script th:src="@{/ajax/libs/bootstrap-table/bootstrap-table.min.js}"></script>
26 26 <script th:src="@{/ajax/libs/bootstrap3-editable/js/bootstrap-editable.js}"></script>
27 27 <script th:src="@{/ajax/libs/bootstrap-table/locale/bootstrap-table-zh-CN.min.js}"></script>
  28 + <script th:src="@{/ajax/libs/bootstrap-table/extensions/editable/bootstrap-table-editable.js}"></script>
28 29 <script th:src="@{/ajax/libs/bootstrap-table/extensions/mobile/bootstrap-table-mobile.min.js}"></script>
29 30 <script th:src="@{/ajax/libs/bootstrap-table/extensions/toolbar/bootstrap-table-toolbar.min.js}"></script>
30 31 <!-- jquery-validate 表单验证插件 -->
... ...