|
@@ -0,0 +1,237 @@
|
|
|
+package com.jpsoft.prices.modules.base.controller;
|
|
|
+
|
|
|
+import com.github.pagehelper.Page;
|
|
|
+import com.jpsoft.prices.modules.common.utils.PojoUtils;
|
|
|
+import com.jpsoft.prices.modules.common.dto.Sort;
|
|
|
+import com.jpsoft.prices.modules.common.dto.MessageResult;
|
|
|
+import com.jpsoft.prices.modules.base.entity.Invoice;
|
|
|
+import com.jpsoft.prices.modules.base.service.InvoiceService;
|
|
|
+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.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/base/invoice")
|
|
|
+@Api(description = "invoice")
|
|
|
+public class InvoiceController {
|
|
|
+ private Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InvoiceService invoiceService;
|
|
|
+
|
|
|
+ @ApiOperation(value="创建空记录")
|
|
|
+ @GetMapping("create")
|
|
|
+ public MessageResult<Invoice> create(){
|
|
|
+ MessageResult<Invoice> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ Invoice invoice = new Invoice();
|
|
|
+
|
|
|
+ msgResult.setData(invoice);
|
|
|
+ msgResult.setResult(true);
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="添加信息")
|
|
|
+ @PostMapping("add")
|
|
|
+ public MessageResult<Invoice> add(@RequestBody Invoice invoice,@RequestAttribute String subject){
|
|
|
+ MessageResult<Invoice> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ invoice.setId(UUID.randomUUID().toString());
|
|
|
+ invoice.setStatus(false);
|
|
|
+ invoice.setDelFlag(false);
|
|
|
+ invoice.setCreateBy(subject);
|
|
|
+ invoice.setCreateTime(new Date());
|
|
|
+
|
|
|
+ int affectCount = invoiceService.insert(invoice);
|
|
|
+
|
|
|
+ if (affectCount > 0) {
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(invoice);
|
|
|
+ } else {
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("数据库添加失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="获取信息")
|
|
|
+ @GetMapping("edit/{id}")
|
|
|
+ public MessageResult<Invoice> edit(@PathVariable("id") String id){
|
|
|
+ MessageResult<Invoice> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ Invoice invoice = invoiceService.get(id);
|
|
|
+
|
|
|
+ if (invoice != null) {
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(invoice);
|
|
|
+ } else {
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("数据库不存在该记录!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="更新用户")
|
|
|
+ @PostMapping("update")
|
|
|
+ public MessageResult<Invoice> update(@RequestBody Invoice invoice,@RequestAttribute String subject){
|
|
|
+ MessageResult<Invoice> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ invoice.setUpdateBy(subject);
|
|
|
+ invoice.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ int affectCount = invoiceService.update(invoice);
|
|
|
+
|
|
|
+ if (affectCount > 0) {
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(invoice);
|
|
|
+ } else {
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("数据库更新失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="删除")
|
|
|
+ @PostMapping("delete/{id}")
|
|
|
+ public MessageResult<Integer> delete(@PathVariable("id") String id,@RequestAttribute String subject){
|
|
|
+ MessageResult<Integer> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ Invoice invoice = invoiceService.get(id);
|
|
|
+ invoice.setDelFlag(true);
|
|
|
+ invoice.setUpdateBy(subject);
|
|
|
+ invoice.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ int affectCount = invoiceService.update(invoice);
|
|
|
+
|
|
|
+ if (affectCount > 0) {
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(affectCount);
|
|
|
+ } else {
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("删除失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation(value="批量删除")
|
|
|
+ @PostMapping("batchDelete")
|
|
|
+ public MessageResult<Integer> batchDelete(@RequestBody List<String> idList,@RequestAttribute String subject){
|
|
|
+ MessageResult<Integer> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ int affectCount = 0;
|
|
|
+
|
|
|
+ for (String id : idList) {
|
|
|
+ Invoice invoice = invoiceService.get(id);
|
|
|
+ invoice.setDelFlag(true);
|
|
|
+ invoice.setUpdateBy(subject);
|
|
|
+ invoice.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ affectCount += invoiceService.update(invoice);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (affectCount > 0) {
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(affectCount);
|
|
|
+ } else {
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("删除失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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 shipment, String recipient, String recipientTelephone, String recipientEntity, String recipientAddress, Boolean status,
|
|
|
+ @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(shipment) && !"null".equals(shipment)) {
|
|
|
+ searchParams.put("shipment",shipment);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(recipient)) {
|
|
|
+ searchParams.put("recipient","%" + recipient + "%");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(recipientTelephone)) {
|
|
|
+ searchParams.put("recipientTelephone","%" + recipientTelephone + "%");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(recipientEntity)) {
|
|
|
+ searchParams.put("recipientEntity","%" + recipientEntity + "%");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(recipientAddress)) {
|
|
|
+ searchParams.put("recipientAddress","%" + recipientAddress + "%");
|
|
|
+ }
|
|
|
+ if (status != null) {
|
|
|
+ searchParams.put("status",status);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Sort> sortList = new ArrayList<>();
|
|
|
+ sortList.add(new Sort("status_","asc"));
|
|
|
+ sortList.add(new Sort("shipment_","asc"));
|
|
|
+
|
|
|
+ Page<Invoice> page = invoiceService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
|
|
|
+
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(PojoUtils.pageWrapper(page));
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+}
|