|
@@ -0,0 +1,329 @@
|
|
|
+package com.jpsoft.order.modules.base.controller;
|
|
|
+
|
|
|
+import com.github.pagehelper.Page;
|
|
|
+import com.jpsoft.order.config.OSSConfig;
|
|
|
+import com.jpsoft.order.modules.common.utils.OSSUtil;
|
|
|
+import com.jpsoft.order.modules.common.utils.POIUtils;
|
|
|
+import com.jpsoft.order.modules.common.utils.PojoUtils;
|
|
|
+import com.jpsoft.order.modules.common.dto.Sort;
|
|
|
+import com.jpsoft.order.modules.common.dto.MessageResult;
|
|
|
+import com.jpsoft.order.modules.base.entity.OrderForm;
|
|
|
+import com.jpsoft.order.modules.base.service.OrderFormService;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
+import io.swagger.annotations.ApiImplicitParams;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/base/orderForm")
|
|
|
+@Api(description = "orderForm")
|
|
|
+public class OrderFormController {
|
|
|
+ private Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OSSConfig ossConfig;
|
|
|
+ @Autowired
|
|
|
+ private OrderFormService orderFormService;
|
|
|
+
|
|
|
+ @ApiOperation(value="创建空记录")
|
|
|
+ @GetMapping("create")
|
|
|
+ public MessageResult<OrderForm> create(){
|
|
|
+ MessageResult<OrderForm> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ OrderForm orderForm = new OrderForm();
|
|
|
+
|
|
|
+ msgResult.setData(orderForm);
|
|
|
+ msgResult.setResult(true);
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="添加信息")
|
|
|
+ @PostMapping("add")
|
|
|
+ public MessageResult<OrderForm> add(@RequestBody OrderForm orderForm,@RequestAttribute String subject){
|
|
|
+ MessageResult<OrderForm> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ orderForm.setId(UUID.randomUUID().toString());
|
|
|
+ orderForm.setDelFlag(false);
|
|
|
+ orderForm.setCreateBy(subject);
|
|
|
+ orderForm.setCreateTime(new Date());
|
|
|
+
|
|
|
+ int affectCount = orderFormService.insert(orderForm);
|
|
|
+
|
|
|
+ if (affectCount > 0) {
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(orderForm);
|
|
|
+ } 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<OrderForm> edit(@PathVariable("id") String id){
|
|
|
+ MessageResult<OrderForm> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ OrderForm orderForm = orderFormService.get(id);
|
|
|
+
|
|
|
+ if (orderForm != null) {
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(orderForm);
|
|
|
+ } 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<OrderForm> update(@RequestBody OrderForm orderForm,@RequestAttribute String subject){
|
|
|
+ MessageResult<OrderForm> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ orderForm.setUpdateBy(subject);
|
|
|
+ orderForm.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ int affectCount = orderFormService.update(orderForm);
|
|
|
+
|
|
|
+ if (affectCount > 0) {
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(orderForm);
|
|
|
+ } 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 {
|
|
|
+ OrderForm orderForm = orderFormService.get(id);
|
|
|
+ orderForm.setDelFlag(true);
|
|
|
+ orderForm.setUpdateBy(subject);
|
|
|
+ orderForm.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ int affectCount = orderFormService.update(orderForm);
|
|
|
+
|
|
|
+ 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) {
|
|
|
+ OrderForm orderForm = orderFormService.get(id);
|
|
|
+ orderForm.setDelFlag(true);
|
|
|
+ orderForm.setUpdateBy(subject);
|
|
|
+ orderForm.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ affectCount += orderFormService.update(orderForm);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 id,
|
|
|
+ @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
|
|
|
+ @RequestParam(value="pageSize",defaultValue="20") int pageSize,
|
|
|
+ @RequestAttribute String subject){
|
|
|
+
|
|
|
+ //当前用户ID
|
|
|
+ System.out.println(subject);
|
|
|
+
|
|
|
+ MessageResult<Map> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ Map<String,Object> searchParams = new HashMap<>();
|
|
|
+
|
|
|
+ List<Sort> sortList = new ArrayList<>();
|
|
|
+ sortList.add(new Sort("id_","asc"));
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(id)) {
|
|
|
+ searchParams.put("id","%" + id + "%");
|
|
|
+ }
|
|
|
+
|
|
|
+ Page<OrderForm> page = orderFormService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
|
|
|
+
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(PojoUtils.pageWrapper(page));
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="导入订单")
|
|
|
+ @PostMapping("importXls")
|
|
|
+ public MessageResult<String> importXls(MultipartFile uploadFile, @RequestAttribute String subject){
|
|
|
+ MessageResult<String> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ POIUtils poiUtils = new POIUtils(uploadFile.getInputStream());
|
|
|
+ Sheet sheet1 = poiUtils.getSheetAt(0);
|
|
|
+
|
|
|
+ int affectCount = 0;
|
|
|
+ int failCount = 0;
|
|
|
+ int validateColIndex = 14;
|
|
|
+
|
|
|
+ for(int rowIndex=1; rowIndex<=sheet1.getLastRowNum(); rowIndex++){
|
|
|
+ try {
|
|
|
+ String strBatch = poiUtils.getCellValue(0,rowIndex,0).toString();
|
|
|
+ String strSerialNo = poiUtils.getCellValue(0,rowIndex,1).toString();
|
|
|
+ String strComplainant = poiUtils.getCellValue(0,rowIndex,2).toString();
|
|
|
+ String strComplainantPhone = poiUtils.getCellValue(0,rowIndex,3).toString();
|
|
|
+ String strProblem = poiUtils.getCellValue(0,rowIndex,4).toString();
|
|
|
+ String strArea = poiUtils.getCellValue(0,rowIndex,5).toString();
|
|
|
+ String strSpecialClass = poiUtils.getCellValue(0,rowIndex,6).toString();
|
|
|
+ String strSuggestedDate = poiUtils.getCellValue(0,rowIndex,7).toString();
|
|
|
+ String strOrg = poiUtils.getCellValue(0,rowIndex,8).toString();
|
|
|
+ String strWarnDate1 = poiUtils.getCellValue(0,rowIndex,9).toString();
|
|
|
+ String strWarnDate2 = poiUtils.getCellValue(0,rowIndex,10).toString();
|
|
|
+ String strWarnDate3 = poiUtils.getCellValue(0,rowIndex,11).toString();
|
|
|
+ String strAllotedDate = poiUtils.getCellValue(0,rowIndex,12).toString();
|
|
|
+ String strRemark = poiUtils.getCellValue(0,rowIndex,13).toString();
|
|
|
+
|
|
|
+ //案件信息
|
|
|
+// Incident incident = new Incident();
|
|
|
+// incident.setId(UUID.randomUUID().toString());
|
|
|
+
|
|
|
+// if(StringUtils.isNotEmpty(strSuggestedDate)){
|
|
|
+// incident.setSuggestedDate(sdf.parse(strSuggestedDate));
|
|
|
+// }
|
|
|
+// else{
|
|
|
+// sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("请填写建议办结时限!");
|
|
|
+// failCount++;
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+
|
|
|
+// incidentService.insert(incident);
|
|
|
+
|
|
|
+ affectCount++;
|
|
|
+ }
|
|
|
+ catch(Exception innerEx){
|
|
|
+ logger.error(innerEx.getMessage(),innerEx);
|
|
|
+ failCount++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (failCount>0){
|
|
|
+ //有导入失败的记录
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("数据成功导入" + affectCount + "条,有" + failCount + "条数据未导入成功,错误原因请查看报表。");
|
|
|
+
|
|
|
+ //todo 只保留错误数据的sheet
|
|
|
+ Workbook wb = poiUtils.exportErrorXls(0,validateColIndex,1 + affectCount + failCount);
|
|
|
+
|
|
|
+ //todo 将wb保存到oss
|
|
|
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
|
+ wb.write(output);
|
|
|
+
|
|
|
+ byte[] buffer = output.toByteArray();
|
|
|
+ ByteArrayInputStream input = new ByteArrayInputStream(buffer);
|
|
|
+
|
|
|
+ //格式化holidayInfo
|
|
|
+ SimpleDateFormat sim = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
+ String fileName = "error" + sim.format(new Date()) + ".xls";
|
|
|
+ String downloadUrl = OSSUtil.upload(ossConfig,"excellent",fileName,input);
|
|
|
+
|
|
|
+ //todo 返回导入失败报表下载链接
|
|
|
+ msgResult.setData(downloadUrl);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setMessage("数据成功导入" + affectCount + "条");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+}
|