优化算法
This commit is contained in:
parent
6ba718dcc5
commit
aa0671992f
|
|
@ -4,10 +4,14 @@ import com.alibaba.excel.EasyExcel;
|
||||||
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
|
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
|
||||||
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
|
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
|
||||||
import com.jinrui.assembly.utils.result.ResultObject;
|
import com.jinrui.assembly.utils.result.ResultObject;
|
||||||
|
import com.jinrui.assembly.utils.result.ResultUtil;
|
||||||
|
import com.jinrui.assembly.utils.text.StringUtils;
|
||||||
import com.jinrui.core.model.dto.admin.SalesCreateDTO;
|
import com.jinrui.core.model.dto.admin.SalesCreateDTO;
|
||||||
import com.jinrui.core.model.dto.admin.SalesDTO;
|
import com.jinrui.core.model.dto.admin.SalesDTO;
|
||||||
|
import com.jinrui.core.model.entity.MarriageCode;
|
||||||
import com.jinrui.core.model.excel.MarriageSalesModel;
|
import com.jinrui.core.model.excel.MarriageSalesModel;
|
||||||
import com.jinrui.core.model.excel.MarriageTotalModel;
|
import com.jinrui.core.model.excel.MarriageTotalModel;
|
||||||
|
import com.jinrui.core.service.IMarriageCodeService;
|
||||||
import com.jinrui.core.service.IMarriageSalesService;
|
import com.jinrui.core.service.IMarriageSalesService;
|
||||||
import com.jinrui.core.util.excel.ImplProgressReportSheetWriteHandler;
|
import com.jinrui.core.util.excel.ImplProgressReportSheetWriteHandler;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
@ -19,7 +23,13 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Base64;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@RequestMapping("admin/sales")
|
@RequestMapping("admin/sales")
|
||||||
|
|
@ -29,6 +39,9 @@ public class AdminSalesController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private IMarriageSalesService marriageSalesService;
|
private IMarriageSalesService marriageSalesService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IMarriageCodeService marriageCodeService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页获取业主列表
|
* 分页获取业主列表
|
||||||
*/
|
*/
|
||||||
|
|
@ -126,4 +139,68 @@ public class AdminSalesController {
|
||||||
log.error("导出站点异常", e);
|
log.error("导出站点异常", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/saveSignImages")
|
||||||
|
public ResultObject saveSignImages() {
|
||||||
|
File dir = new File("signImage");
|
||||||
|
if (!dir.exists()) {
|
||||||
|
dir.mkdirs();
|
||||||
|
}
|
||||||
|
int saved = 0;
|
||||||
|
int total = 0;
|
||||||
|
int pageIndex = 1;
|
||||||
|
int pageSize = 20;
|
||||||
|
LambdaQueryWrapper<MarriageCode> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.orderByAsc(MarriageCode::getId);
|
||||||
|
SimpleDateFormat format = new SimpleDateFormat("yyyyMM");
|
||||||
|
while (true) {
|
||||||
|
Page<MarriageCode> page = new Page<>(pageIndex, pageSize);
|
||||||
|
Page<MarriageCode> data = marriageCodeService.page(page, wrapper);
|
||||||
|
List<MarriageCode> records = data.getRecords();
|
||||||
|
if (records == null || records.isEmpty()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
for (MarriageCode mc : records) {
|
||||||
|
total++;
|
||||||
|
log.info("处理签名图片 id={} getSignImage is null :{},time:{}", mc.getId(),StringUtils.isBlank(mc.getSignImage()),mc.getReceiveTime());
|
||||||
|
String s = mc.getSignImage();
|
||||||
|
if (StringUtils.isBlank(s)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (mc.getReceiveTime()==null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String date = format.format(mc.getReceiveTime());
|
||||||
|
File datedir = new File(dir,date);
|
||||||
|
if (!datedir.exists()) {
|
||||||
|
datedir.mkdirs();
|
||||||
|
}
|
||||||
|
String b64 = s;
|
||||||
|
int idx = s.indexOf(",");
|
||||||
|
if (s.startsWith("data:image") && idx > -1) {
|
||||||
|
b64 = s.substring(idx + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
byte[] bytes = Base64.getDecoder().decode(b64);
|
||||||
|
File out = new File(datedir, "sign_" + mc.getId() + ".png");
|
||||||
|
try (FileOutputStream fos = new FileOutputStream(out)) {
|
||||||
|
fos.write(bytes);
|
||||||
|
}
|
||||||
|
mc.setSignImage("");
|
||||||
|
marriageCodeService.saveOrUpdate(mc);
|
||||||
|
saved++;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
log.error("写入签名图片失败 id={}", mc.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pageIndex++;
|
||||||
|
}
|
||||||
|
java.util.Map<String, Object> result = new java.util.HashMap<>();
|
||||||
|
result.put("dir", dir.getAbsolutePath());
|
||||||
|
result.put("saved", saved);
|
||||||
|
result.put("total", total);
|
||||||
|
return ResultUtil.success(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,10 @@ import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
@ -200,6 +203,7 @@ public class MarriageActivityServiceImpl extends ServiceImpl<MarriageActivityMap
|
||||||
if (!CollectionUtils.isEmpty(marriageCodePage.getRecords())) {
|
if (!CollectionUtils.isEmpty(marriageCodePage.getRecords())) {
|
||||||
for (MarriageCode record : marriageCodePage.getRecords()) {
|
for (MarriageCode record : marriageCodePage.getRecords()) {
|
||||||
MarriageCodePageVO vo = new MarriageCodePageVO();
|
MarriageCodePageVO vo = new MarriageCodePageVO();
|
||||||
|
getMarriageSign(record);
|
||||||
BeanUtils.copyProperties(record, vo);
|
BeanUtils.copyProperties(record, vo);
|
||||||
|
|
||||||
if (record.getReceiveMoney() != null) {
|
if (record.getReceiveMoney() != null) {
|
||||||
|
|
@ -243,6 +247,7 @@ public class MarriageActivityServiceImpl extends ServiceImpl<MarriageActivityMap
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (MarriageCode record : marriageCodeList) {
|
for (MarriageCode record : marriageCodeList) {
|
||||||
|
getMarriageSign(record);
|
||||||
MarriageCodeRecodeModel model = new MarriageCodeRecodeModel();
|
MarriageCodeRecodeModel model = new MarriageCodeRecodeModel();
|
||||||
model.setSignImage("");
|
model.setSignImage("");
|
||||||
model.setCode(record.getCode());
|
model.setCode(record.getCode());
|
||||||
|
|
@ -274,4 +279,27 @@ public class MarriageActivityServiceImpl extends ServiceImpl<MarriageActivityMap
|
||||||
Long money = 6000L;
|
Long money = 6000L;
|
||||||
System.out.println(MoneyUtils.calculatePortions(new BigDecimal(totalMoney.toString()), new BigDecimal(money.toString())));
|
System.out.println(MoneyUtils.calculatePortions(new BigDecimal(totalMoney.toString()), new BigDecimal(money.toString())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void getMarriageSign(MarriageCode marriageCode) {
|
||||||
|
File file = new File("signImage");
|
||||||
|
if (!file.exists()) {
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
SimpleDateFormat format = new SimpleDateFormat("yyyyMM");
|
||||||
|
String date = format.format(marriageCode.getReceiveTime());
|
||||||
|
File dir = new File(file, date);
|
||||||
|
if (!dir.exists()) {
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
File imgFile = new File(dir, "sign_" + marriageCode.getId() + ".png");
|
||||||
|
if (!imgFile.exists()) {
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
byte[] bytes = Files.readAllBytes(imgFile.toPath());
|
||||||
|
String b64 = java.util.Base64.getEncoder().encodeToString(bytes);
|
||||||
|
marriageCode.setSignImage( b64);
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,12 +28,11 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@RequestMapping("/marriage/")
|
@RequestMapping("/marriage/")
|
||||||
|
|
@ -112,6 +111,7 @@ public class MarriageController {
|
||||||
System.out.println(substring);
|
System.out.println(substring);
|
||||||
System.out.println(substring1);
|
System.out.println(substring1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean checkMarriageNo(String marriageNo) {
|
public Boolean checkMarriageNo(String marriageNo) {
|
||||||
boolean canReceive = false;
|
boolean canReceive = false;
|
||||||
String code = marriageNo.substring(0, 6);
|
String code = marriageNo.substring(0, 6);
|
||||||
|
|
@ -121,6 +121,7 @@ public class MarriageController {
|
||||||
}
|
}
|
||||||
return canReceive;
|
return canReceive;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/receiveCheck")
|
@PostMapping("/receiveCheck")
|
||||||
public ResultObject receiveCheck(@RequestBody MarriageCodeDTO dto) {
|
public ResultObject receiveCheck(@RequestBody MarriageCodeDTO dto) {
|
||||||
if (StringUtils.isBlank(dto.getMarriageNo())) {
|
if (StringUtils.isBlank(dto.getMarriageNo())) {
|
||||||
|
|
@ -254,12 +255,54 @@ public class MarriageController {
|
||||||
code1.setMarriageNo(dto.getMarriageNo());
|
code1.setMarriageNo(dto.getMarriageNo());
|
||||||
code1.setReceiveName(dto.getReceiveName());
|
code1.setReceiveName(dto.getReceiveName());
|
||||||
code1.setReceiveMobile(dto.getReceiveMobile());
|
code1.setReceiveMobile(dto.getReceiveMobile());
|
||||||
code1.setSignImage(dto.getSignImage());
|
|
||||||
|
|
||||||
|
// code1.setSignImage(dto.getSignImage());
|
||||||
code1.setSalesNo(dto.getSalesNo());
|
code1.setSalesNo(dto.getSalesNo());
|
||||||
code1.setReceiveMoney(6000);
|
code1.setReceiveMoney(6000);
|
||||||
code1.setReceiveTime(now);
|
code1.setReceiveTime(now);
|
||||||
code1.setStatus(1);
|
code1.setStatus(1);
|
||||||
iMarriageCodeService.updateById(code1);
|
iMarriageCodeService.updateById(code1);
|
||||||
|
savaSign(code1, dto.getSignImage());
|
||||||
return ResultUtil.success();
|
return ResultUtil.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void savaSign(MarriageCode mc, String s) {
|
||||||
|
File dir = new File("signImage");
|
||||||
|
if (!dir.exists()) {
|
||||||
|
dir.mkdirs();
|
||||||
}
|
}
|
||||||
|
log.info("处理签名图片 id={} getSignImage is null :{},time:{}", mc.getId(), StringUtils.isBlank(s), mc.getReceiveTime());
|
||||||
|
if (com.jinrui.assembly.utils.text.StringUtils.isBlank(s)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (mc.getReceiveTime() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SimpleDateFormat format = new SimpleDateFormat("yyyyMM");
|
||||||
|
String date = format.format(mc.getReceiveTime());
|
||||||
|
File datedir = new File(dir, date);
|
||||||
|
if (!datedir.exists()) {
|
||||||
|
datedir.mkdirs();
|
||||||
|
}
|
||||||
|
String b64 = s;
|
||||||
|
int idx = s.indexOf(",");
|
||||||
|
if (s.startsWith("data:image") && idx > -1) {
|
||||||
|
b64 = s.substring(idx + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
byte[] bytes = Base64.getDecoder().decode(b64);
|
||||||
|
File out = new File(datedir, "sign_" + mc.getId() + ".png");
|
||||||
|
try (FileOutputStream fos = new FileOutputStream(out)) {
|
||||||
|
fos.write(bytes);
|
||||||
|
}
|
||||||
|
mc.setSignImage(null);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
log.error("写入签名图片失败 id={}", mc.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue