package zy.cloud.wms.manager.controller;
|
|
import com.alibaba.fastjson.JSONArray;
|
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.common.DateUtils;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.BeanUtils;
|
import zy.cloud.wms.manager.dto.DiffValDto;
|
import zy.cloud.wms.manager.entity.DiffVal;
|
import zy.cloud.wms.manager.entity.Mat;
|
import zy.cloud.wms.manager.mapper.MatMapper;
|
import zy.cloud.wms.manager.service.DiffValService;
|
import com.core.annotations.ManagerAuth;
|
import com.core.common.BaseRes;
|
import com.core.common.Cools;
|
import com.core.common.R;
|
import zy.cloud.wms.common.web.BaseController;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.util.*;
|
|
@Slf4j
|
@RestController
|
public class DiffValController extends BaseController {
|
|
@Autowired
|
private DiffValService diffValService;
|
@Autowired
|
private MatMapper matMapper;
|
|
@RequestMapping(value = "/diffVal/{id}/auth")
|
@ManagerAuth
|
public R get(@PathVariable("id") String id) {
|
return R.ok(diffValService.selectById(String.valueOf(id)));
|
}
|
|
@RequestMapping(value = "/diffVal/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 Map<String, Object> param,
|
@RequestParam(defaultValue = "0")Integer includeZero){
|
EntityWrapper<DiffVal> wrapper = new EntityWrapper<>();
|
param.remove("includeZero");
|
excludeTrash(param);
|
convert(param, wrapper);
|
if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));}
|
//朱航帅
|
log.info("includeZero的值是"+includeZero);
|
if (includeZero != 0){
|
wrapper.ne("val",0.0);
|
}
|
List<DiffValDto> dvd = new ArrayList<>();
|
Page<DiffVal> diffValPage = diffValService.selectPage(new Page<>(curr, limit), wrapper);
|
for (DiffVal record : diffValPage.getRecords()) {
|
|
Mat mat = matMapper.selectByMatnr(record.getMatnr());
|
DiffValDto diffValDto = new DiffValDto();
|
BeanUtils.copyProperties(record,diffValDto,DiffValDto.class);
|
diffValDto.setMaktx(mat.getMaktx());
|
log.info("集合中的每条数据"+diffValDto);
|
dvd.add(diffValDto);
|
|
}
|
Page<DiffValDto> diffValDtoPage = new Page<>();
|
diffValDtoPage.setRecords(dvd);
|
|
return R.ok(diffValDtoPage);
|
}
|
|
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 = "/diffVal/add/auth")
|
@ManagerAuth
|
public R add(DiffVal diffVal) {
|
diffValService.insert(diffVal);
|
return R.ok();
|
}
|
|
@RequestMapping(value = "/diffVal/update/auth")
|
@ManagerAuth
|
public R update(DiffVal diffVal){
|
if (Cools.isEmpty(diffVal) || null==diffVal.getMatnr()){
|
return R.error();
|
}
|
diffValService.updateById(diffVal);
|
return R.ok();
|
}
|
|
@RequestMapping(value = "/diffVal/delete/auth")
|
@ManagerAuth
|
public R delete(@RequestParam(value="ids[]") Long[] ids){
|
for (Long id : ids){
|
diffValService.deleteById(id);
|
}
|
return R.ok();
|
}
|
|
@RequestMapping(value = "/diffVal/export/auth")
|
@ManagerAuth
|
public R export(@RequestBody JSONObject param){
|
EntityWrapper<DiffVal> wrapper = new EntityWrapper<>();
|
List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class);
|
Map<String, Object> map = excludeTrash(param.getJSONObject("diffVal"));
|
convert(map, wrapper);
|
List<DiffVal> list = diffValService.selectList(wrapper);
|
return R.ok(exportSupport(list, fields));
|
}
|
|
@RequestMapping(value = "/diffValQuery/auth")
|
@ManagerAuth
|
public R query(String condition) {
|
EntityWrapper<DiffVal> wrapper = new EntityWrapper<>();
|
wrapper.like("id", condition);
|
Page<DiffVal> page = diffValService.selectPage(new Page<>(0, 10), wrapper);
|
List<Map<String, Object>> result = new ArrayList<>();
|
for (DiffVal diffVal : page.getRecords()){
|
Map<String, Object> map = new HashMap<>();
|
map.put("id", diffVal.getMatnr());
|
map.put("value", diffVal.getMatnr());
|
result.add(map);
|
}
|
return R.ok(result);
|
}
|
|
@RequestMapping(value = "/diffVal/check/column/auth")
|
@ManagerAuth
|
public R query(@RequestBody JSONObject param) {
|
Wrapper<DiffVal> wrapper = new EntityWrapper<DiffVal>().eq(humpToLine(String.valueOf(param.get("key"))), param.get("val"));
|
if (null != diffValService.selectOne(wrapper)){
|
return R.parse(BaseRes.REPEAT).add(getComment(DiffVal.class, String.valueOf(param.get("key"))));
|
}
|
return R.ok();
|
}
|
|
@RequestMapping("/diffVal/getList")
|
@ManagerAuth
|
public R getList(@RequestParam(required = false) String condition,
|
@RequestParam Integer type) {
|
List<Map<String, Object>> result = new ArrayList<>();
|
HashMap<String, Object> trueResult = new HashMap<>();
|
trueResult.put("val","0");
|
HashMap<String, Object> falseResult = new HashMap<>();
|
falseResult.put("val","1");
|
result.add(trueResult);
|
result.add(falseResult);
|
return R.ok().add(result);
|
}
|
}
|