package com.zy.ints.controller;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.mapper.Wrapper;
|
import com.baomidou.mybatisplus.plugins.Page;
|
import com.core.annotations.ManagerAuth;
|
import com.core.common.BaseRes;
|
import com.core.common.Cools;
|
import com.core.common.DateUtils;
|
import com.core.common.R;
|
import com.core.exception.CoolException;
|
import com.zy.common.web.BaseController;
|
import com.zy.ints.entity.WaitMatin;
|
import com.zy.ints.entity.WaitMatout;
|
import com.zy.ints.service.WaitMatoutService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.util.*;
|
|
@RestController
|
public class WaitMatoutController extends BaseController {
|
|
@Autowired
|
private WaitMatoutService waitMatoutService;
|
|
@RequestMapping(value = "/waitMatout/{id}/auth")
|
@ManagerAuth
|
public R get(@PathVariable("id") String id) {
|
return R.ok(waitMatoutService.selectById(String.valueOf(id)));
|
}
|
|
|
@RequestMapping(value = "/waitMatout/head/page/auth")
|
@ManagerAuth
|
public R headPage(@RequestParam(defaultValue = "1")Integer curr,
|
@RequestParam(defaultValue = "10")Integer limit,
|
@RequestParam Map<String, Object> param){
|
if (!Cools.isEmpty(param.get("appe_time"))){
|
String val = String.valueOf(param.get("appe_time"));
|
if (val.contains(RANGE_TIME_LINK)) {
|
String[] dates = val.split(RANGE_TIME_LINK);
|
param.put("startTime", DateUtils.convert(dates[0]));
|
param.put("endTime", DateUtils.convert(dates[1]));
|
param.remove("appe_time");
|
}
|
}
|
return R.ok(waitMatoutService.getHeadPage(toPage(curr, limit, param, WaitMatout.class)));
|
}
|
|
@RequestMapping(value = "/waitMatout/list/auth")
|
@ManagerAuth
|
public R list(@RequestParam(defaultValue = "1")Integer curr,
|
@RequestParam(defaultValue = "10")Integer limit,
|
@RequestParam(required = false)String orderByField,
|
@RequestParam(required = false)String orderByType,
|
@RequestParam(required = false)String condition,
|
@RequestParam Map<String, Object> param){
|
EntityWrapper<WaitMatout> wrapper = new EntityWrapper<>();
|
excludeTrash(param);
|
convert(param, wrapper);
|
allLike(WaitMatout.class, param.keySet(), wrapper, condition);
|
if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));}
|
return R.ok(waitMatoutService.selectPage(new Page<>(curr, limit), wrapper));
|
}
|
|
@RequestMapping(value = "/waitMatout/list/auth2")
|
@ManagerAuth
|
public R list(@RequestParam(defaultValue = "1")Integer curr,
|
@RequestParam(defaultValue = "10")Integer limit,
|
@RequestParam(required = false)String orderByField,
|
@RequestParam(required = false)String orderByType,
|
@RequestParam(required = false)String condition,
|
@RequestParam(name = "billNo") String bill_no){
|
EntityWrapper<WaitMatout> wrapper = new EntityWrapper<>();
|
wrapper.eq("bill_no", bill_no);
|
if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));}
|
return R.ok(waitMatoutService.selectPage(new Page<>(curr, limit), wrapper));
|
}
|
|
private void convert(Map<String, Object> map, EntityWrapper wrapper){
|
for (Map.Entry<String, Object> entry : map.entrySet()){
|
String val = String.valueOf(entry.getValue());
|
if (val.contains(RANGE_TIME_LINK)){
|
String[] dates = val.split(RANGE_TIME_LINK);
|
wrapper.ge(entry.getKey(), DateUtils.convert(dates[0]));
|
wrapper.le(entry.getKey(), DateUtils.convert(dates[1]));
|
} else {
|
wrapper.like(entry.getKey(), val);
|
}
|
}
|
}
|
|
@RequestMapping(value = "/waitMatout/add/auth")
|
@ManagerAuth
|
@Transactional
|
public R add(@RequestBody List<WaitMatout> waitMatouts) {
|
if (Cools.isEmpty(waitMatouts)) {
|
return R.parse(BaseRes.PARAM);
|
}
|
if (waitMatoutService.selectCount(new EntityWrapper<WaitMatout>().eq("bill_no", waitMatouts.get(0).getBillNo())) > 0) {
|
return R.error("单据编号已存在");
|
}
|
int i = 1;
|
Date now = new Date();
|
for (WaitMatout waitMatout : waitMatouts) {
|
waitMatout.setSeqNo(i);
|
waitMatout.setAppeTime(now);
|
waitMatout.setAppeUser(getUserId());
|
waitMatout.setModiTime(now);
|
waitMatout.setModiUser(getUserId());
|
if (!waitMatoutService.insert(waitMatout)) {
|
throw new CoolException("添加单据明细失败");
|
}
|
i++;
|
}
|
return R.ok("添加成功");
|
}
|
|
@RequestMapping(value = "/waitMatout/modify/auth")
|
@ManagerAuth
|
@Transactional
|
public R update(@RequestBody List<WaitMatout> waitMatouts){
|
if (Cools.isEmpty(waitMatouts)) {
|
return R.parse(BaseRes.PARAM);
|
}
|
Date now = new Date();
|
List<WaitMatout> oldWaitMatouts = waitMatoutService.selectList(new EntityWrapper<WaitMatout>().eq("bill_no", waitMatouts.get(0).getBillNo()));
|
Date appeTime = oldWaitMatouts!=null?oldWaitMatouts.get(0).getAppeTime():now;
|
Long appeUser = oldWaitMatouts!=null?oldWaitMatouts.get(0).getAppeUser():getUserId();
|
if (!waitMatoutService.delete(new EntityWrapper<WaitMatout>().eq("bill_no", waitMatouts.get(0).getBillNo()))) {
|
return R.error();
|
}
|
int i = 1;
|
for (WaitMatout waitMatout : waitMatouts) {
|
waitMatout.setSeqNo(i);
|
waitMatout.setAppeTime(appeTime);
|
waitMatout.setAppeUser(appeUser);
|
waitMatout.setModiTime(now);
|
waitMatout.setModiUser(getUserId());
|
if (!waitMatoutService.insert(waitMatout)) {
|
throw new CoolException("修改单据明细失败");
|
}
|
i++;
|
}
|
return R.ok("修改成功");
|
}
|
|
@RequestMapping(value = "/waitMatout/detl/list/auth")
|
@ManagerAuth
|
public R detlPage(@RequestParam String billNo){
|
if (Cools.isEmpty(billNo)){
|
return R.parse(BaseRes.PARAM);
|
}
|
List<WaitMatout> waitMatins = waitMatoutService.selectList(new EntityWrapper<WaitMatout>().eq("bill_no", billNo));
|
if (Cools.isEmpty(waitMatins)) {
|
return R.parse(BaseRes.EMPTY);
|
}
|
return R.ok().add(waitMatins);
|
}
|
|
|
|
@RequestMapping(value = "/waitMatout/delete/auth")
|
@ManagerAuth
|
public R delete(@RequestParam String billNo){
|
if (!waitMatoutService.delete(new EntityWrapper<WaitMatout>().eq("bill_no", billNo))) {
|
throw new CoolException("删除单据明细失败");
|
}
|
return R.ok("删除成功");
|
}
|
|
@RequestMapping(value = "/waitMatout/export/auth")
|
@ManagerAuth
|
public R export(@RequestBody JSONObject param){
|
EntityWrapper<WaitMatout> wrapper = new EntityWrapper<>();
|
List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class);
|
Map<String, Object> map = excludeTrash(param.getJSONObject("waitMatout"));
|
convert(map, wrapper);
|
List<WaitMatout> list = waitMatoutService.selectList(wrapper);
|
return R.ok(exportSupport(list, fields));
|
}
|
|
@RequestMapping(value = "/waitMatoutQuery/auth")
|
@ManagerAuth
|
public R query(String condition) {
|
EntityWrapper<WaitMatout> wrapper = new EntityWrapper<>();
|
wrapper.like("mat_no", condition);
|
Page<WaitMatout> page = waitMatoutService.selectPage(new Page<>(0, 10), wrapper);
|
List<Map<String, Object>> result = new ArrayList<>();
|
for (WaitMatout waitMatout : page.getRecords()){
|
Map<String, Object> map = new HashMap<>();
|
map.put("id", waitMatout.getSeqNo());
|
map.put("value", waitMatout.getMatNo());
|
result.add(map);
|
}
|
return R.ok(result);
|
}
|
|
@RequestMapping(value = "/waitMatout/check/column/auth")
|
@ManagerAuth
|
public R query(@RequestBody JSONObject param) {
|
Wrapper<WaitMatout> wrapper = new EntityWrapper<WaitMatout>().eq(humpToLine(String.valueOf(param.get("key"))), param.get("val"));
|
if (null != waitMatoutService.selectOne(wrapper)){
|
return R.parse(BaseRes.REPEAT).add(getComment(WaitMatout.class, String.valueOf(param.get("key"))));
|
}
|
return R.ok();
|
}
|
|
}
|