|
@@ -0,0 +1,186 @@
|
|
|
+package com.jpsoft.printing.modules.base.controller;
|
|
|
+
|
|
|
+import com.github.pagehelper.Page;
|
|
|
+import com.jpsoft.printing.modules.base.entity.Customer;
|
|
|
+import com.jpsoft.printing.modules.base.entity.Work;
|
|
|
+import com.jpsoft.printing.modules.base.service.CustomerService;
|
|
|
+import com.jpsoft.printing.modules.base.service.StockService;
|
|
|
+import com.jpsoft.printing.modules.base.service.WorkService;
|
|
|
+import com.jpsoft.printing.modules.common.utils.PojoUtils;
|
|
|
+import com.jpsoft.printing.modules.common.dto.Sort;
|
|
|
+import com.jpsoft.printing.modules.common.dto.MessageResult;
|
|
|
+import com.jpsoft.printing.modules.base.entity.Account;
|
|
|
+import com.jpsoft.printing.modules.base.service.AccountService;
|
|
|
+import com.jpsoft.printing.modules.sys.service.SysLogService;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/base/account")
|
|
|
+@Api(description = "account")
|
|
|
+public class AccountController {
|
|
|
+ private Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
+ @Autowired
|
|
|
+ private SysLogService sysLogService;
|
|
|
+ @Autowired
|
|
|
+ private CustomerService customerService;
|
|
|
+ @Autowired
|
|
|
+ private WorkService workService;
|
|
|
+ @Autowired
|
|
|
+ private StockService stockService;
|
|
|
+ @Autowired
|
|
|
+ private AccountService accountService;
|
|
|
+
|
|
|
+ @ApiOperation(value="获取信息")
|
|
|
+ @GetMapping("edit/{id}")
|
|
|
+ public MessageResult edit(@PathVariable("id") String id){
|
|
|
+ MessageResult msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ Account account = accountService.get(id);
|
|
|
+
|
|
|
+ if (account != null) {
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(account);
|
|
|
+ } else {
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("数据库不存在该记录!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="删除")
|
|
|
+ @PostMapping("delete/{id}")
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public MessageResult<Integer> delete(@PathVariable("id") String id,@RequestAttribute String subject,HttpServletRequest request){
|
|
|
+ Long begin = System.currentTimeMillis();
|
|
|
+ MessageResult<Integer> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ Account account = accountService.get(id);
|
|
|
+ account.setDelFlag(true);
|
|
|
+ account.setUpdateBy(subject);
|
|
|
+ account.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ int affectCount = accountService.update(account);
|
|
|
+
|
|
|
+ if (affectCount > 0) {
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(affectCount);
|
|
|
+ msgResult.setMessage("删除成功");
|
|
|
+ } else {
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("删除失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ Long end = System.currentTimeMillis();
|
|
|
+ sysLogService.addLog(subject,request.getRemoteAddr(),request.getServletPath(),id,end-begin,null,msgResult.getMessage());
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="列表")
|
|
|
+ @RequestMapping(value = "pageList",method = RequestMethod.POST)
|
|
|
+ public MessageResult<Map> pageList(
|
|
|
+ String id,
|
|
|
+ @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
|
|
|
+ @RequestParam(value="pageSize",defaultValue="20") int pageSize,
|
|
|
+ @RequestAttribute String subject){
|
|
|
+ MessageResult<Map> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ Map<String,Object> searchParams = new HashMap<>();
|
|
|
+ if (StringUtils.isNotEmpty(id)) {
|
|
|
+ searchParams.put("id","%" + id + "%");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Sort> sortList = new ArrayList<>();
|
|
|
+ sortList.add(new Sort("id_","asc"));
|
|
|
+
|
|
|
+ Page<Account> page = accountService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
|
|
|
+
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(PojoUtils.pageWrapper(page));
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="建立信息")
|
|
|
+ @GetMapping("createBill/{id}")
|
|
|
+ public MessageResult createBill(@PathVariable("id") String id){
|
|
|
+ MessageResult msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ Work work = workService.get(id);
|
|
|
+
|
|
|
+ if (work != null) {
|
|
|
+ BigDecimal actualQuantity = stockService.getActualQuantity(id);
|
|
|
+ if(actualQuantity != null) {
|
|
|
+ work.setActualQuantity(actualQuantity);
|
|
|
+
|
|
|
+ BigDecimal rollQuantity = stockService.getRollQuantity(id);
|
|
|
+ work.setRollQuantity(rollQuantity);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ work.setActualQuantity(new BigDecimal(0));
|
|
|
+ work.setRollQuantity(new BigDecimal(0));
|
|
|
+ }
|
|
|
+ work.setClothQuantity(work.getActualQuantity().subtract(work.getEstimateQuantity()));
|
|
|
+
|
|
|
+ Customer customer = customerService.get(work.getCustomerId());
|
|
|
+ if(customer != null){
|
|
|
+ String allName = "";
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(customer.getCompany())){
|
|
|
+ allName = customer.getName() + "(" + customer.getCompany() + ")";
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ allName = customer.getName();
|
|
|
+ }
|
|
|
+
|
|
|
+ work.setCustomerName(allName);
|
|
|
+ }
|
|
|
+
|
|
|
+ work.setActualAmount(work.getActualQuantity().multiply(work.getUnitPrice()));
|
|
|
+ work.setClothAmount(work.getClothQuantity().multiply(work.getClothPrice()));
|
|
|
+ work.setRollAmount(work.getRollQuantity().multiply(work.getWages()));
|
|
|
+ work.setTotalAmount(work.getActualAmount().add(work.getClothAmount()).add(work.getRollAmount()));
|
|
|
+
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(work);
|
|
|
+ } else {
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("数据库不存在该记录!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+}
|