package com.zy.asrs.controller;
|
|
import com.alibaba.excel.EasyExcel;
|
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
|
import com.baomidou.mybatisplus.plugins.Page;
|
import com.core.annotations.ManagerAuth;
|
import com.core.common.R;
|
import com.core.exception.CoolException;
|
import com.zy.asrs.entity.LocDetl;
|
import com.zy.asrs.entity.MatCode;
|
import com.zy.asrs.service.LocDetlService;
|
import com.zy.asrs.service.MatCodeService;
|
import com.zy.asrs.utils.VersionUtils;
|
import com.zy.common.web.BaseController;
|
import com.zy.ints.entity.StockSync;
|
import com.zy.ints.service.StockSyncService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.IOException;
|
import java.net.URLEncoder;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* Created by vincent on 2021/4/2
|
*/
|
@RestController
|
public class StatisController extends BaseController {
|
|
@Autowired
|
private MatCodeService matCodeService;
|
@Autowired
|
private LocDetlService locDetlService;
|
@Autowired
|
StockSyncService stockSyncService;
|
|
// 库存统计 ------------------------------------------------------------------------------------------
|
|
@RequestMapping(value = "/stock/statis/auth")
|
@ManagerAuth
|
public R stockStatis(@RequestParam(defaultValue = "1")Integer curr,
|
@RequestParam(defaultValue = "14")Integer limit,
|
// @RequestParam(required = false)String condition,
|
@RequestParam Map<String, Object> param) {
|
Page<LocDetl> stockStatis = locDetlService.getStockStatis(toPage(curr, limit, param, LocDetl.class));
|
// for (LocDetl locDetl : stockStatis.getRecords()) {
|
// MatCode mat = matCodeService.selectOne(new EntityWrapper<MatCode>().eq("mat_no",locDetl.getMatNo()));
|
//// MatCode mat = matCodeService.selectById(locDetl.getMatnr());
|
// if (mat != null) {
|
// VersionUtils.setLocDetl(locDetl, mat);
|
// }
|
// }
|
return R.ok().add(stockStatis);
|
}
|
|
//库位报表导出
|
@RequestMapping(value = "/stock/statis/export")
|
public void stockStatisExport(@RequestParam(required = false) String matNo,
|
@RequestParam(required = false) String matName,
|
@RequestParam(required = false) String supplier,
|
@RequestParam(required = false) String str3,
|
@RequestParam(required = false) String str4,
|
@RequestParam(required = false) String memo,
|
HttpServletResponse response) throws IOException {
|
LocDetl param = new LocDetl();
|
param.setMatNo(matNo!=null ? matNo : "");
|
param.setMatName(matName!=null ? matName : "");
|
param.setSupplier(supplier!=null ? supplier : "");
|
param.setStr3(str3!=null ? str3 : "");
|
param.setStr4(str4!=null ? str4 : "");
|
param.setMemo(memo!=null ? memo : "");
|
|
List<LocDetl> excel = locDetlService.getStockStatisExcel(param);
|
for (LocDetl locDetl : excel) {
|
MatCode mat = matCodeService.selectById(locDetl.getMatNo());
|
if (mat != null) {
|
VersionUtils.setLocDetl(locDetl, mat);
|
}
|
}
|
response.setContentType("application/vnd.ms-excel");
|
response.setCharacterEncoding("utf-8");
|
String fileName = URLEncoder.encode("库存明细统计报表", "UTF-8");
|
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
|
EasyExcel.write(response.getOutputStream(), LocDetl.class)
|
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
|
.sheet("sheet1")
|
.doWrite(excel);
|
}
|
|
/**
|
* 获取库存同步表数据
|
* @return
|
*/
|
@RequestMapping(value = "/stock/stockSyncCount")
|
@ManagerAuth(memo = "获取库存同步上传清单数量")
|
public R getStockSyncCount() {
|
return R.ok(stockSyncService.getStockSyncCount());
|
}
|
|
/**
|
* 插入数据到库存同步表
|
* @return
|
*/
|
@RequestMapping(value = "/stock/insertStockSync")
|
@ManagerAuth(memo = "同步上传清单数据插入")
|
@Transactional
|
public R insertStockSync() {
|
Date now = new Date();
|
Long userId = getUserId();
|
List<LocDetl> locDetls = locDetlService.getStockSum();
|
for(LocDetl locdetl : locDetls){
|
StockSync stockSync = new StockSync();
|
stockSync.setMatNo(locdetl.getMatNo());
|
stockSync.setMatName(locdetl.getMatName());
|
stockSync.setQty(locdetl.getQty());
|
stockSync.setModiUser(userId);
|
stockSync.setModiTime(now);
|
stockSync.setAppeUser(userId);
|
stockSync.setAppeTime(now);
|
if(!stockSyncService.insert(stockSync)){
|
throw new CoolException("插入同步库存数据失败");
|
}
|
}
|
return R.ok(locDetls.size());
|
}
|
|
/**
|
* 更新数据到库存同步表,先清空再插入
|
* @return
|
*/
|
@RequestMapping(value = "/stock/updateStockSync")
|
@ManagerAuth(memo = "清空同步上传数据并插入")
|
@Transactional
|
public R updateStockSync() {
|
if(!stockSyncService.clearStockSync()){
|
throw new CoolException("同步上传数据清空失败,请联系管理员");
|
}
|
|
Date now = new Date();
|
Long userId = getUserId();
|
List<LocDetl> locDetls = locDetlService.getStockSum();
|
for(LocDetl locdetl : locDetls){
|
StockSync stockSync = new StockSync();
|
stockSync.setMatNo(locdetl.getMatNo());
|
stockSync.setMatName(locdetl.getMatName());
|
stockSync.setQty(locdetl.getQty());
|
stockSync.setModiUser(userId);
|
stockSync.setModiTime(now);
|
stockSync.setAppeUser(userId);
|
stockSync.setAppeTime(now);
|
if(!stockSyncService.insert(stockSync)){
|
throw new CoolException("更新同步库存数据失败");
|
}
|
}
|
return R.ok(locDetls.size());
|
}
|
}
|