| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498 |
- package cn.com.goldenwater.dcproj.service.impl;
- import cn.com.goldenwater.dcproj.dao.AttAdXBaseDao;
- import cn.com.goldenwater.dcproj.dao.AttHystBaseDao;
- import cn.com.goldenwater.dcproj.model.AttAdXBase;
- import cn.com.goldenwater.dcproj.model.AttHystBase;
- import cn.com.goldenwater.dcproj.param.AttAdXBaseParam;
- import cn.com.goldenwater.dcproj.param.AttHystBaseParam;
- import cn.com.goldenwater.dcproj.param.BisInspHystInfoParam;
- import cn.com.goldenwater.dcproj.service.AttHystBaseService;
- import cn.com.goldenwater.core.service.AbstractCrudService;
- import cn.com.goldenwater.dcproj.utils.expExcel.ExportUtil;
- import cn.com.goldenwater.id.util.UuidUtil;
- import com.github.pagehelper.PageHelper;
- import com.github.pagehelper.PageInfo;
- import org.apache.commons.lang3.StringUtils;
- import org.apache.poi.ss.usermodel.Cell;
- import org.apache.poi.ss.usermodel.Row;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.web.multipart.MultipartFile;
- import java.text.DecimalFormat;
- import java.util.*;
- /**
- * @author lune
- * @date 2021-3-2
- */
- @Service
- @Transactional(rollbackFor = Exception.class)
- public class AttHystBaseServiceImpl extends AbstractCrudService<AttHystBase, AttHystBaseParam> implements AttHystBaseService {
- @Autowired
- private AttHystBaseDao attHystBaseDao;
- @Autowired
- private AttAdXBaseDao attAdXBaseDao;
- public AttHystBaseServiceImpl(AttHystBaseDao attHystBaseDao) {
- super(attHystBaseDao);
- this.attHystBaseDao = attHystBaseDao;
- }
- @Override
- public PageInfo<AttHystBase> getListInfo(BisInspHystInfoParam p) {
- PageHelper.startPage(p);
- List<AttHystBase> list = this.attHystBaseDao.findListByParam(p);
- PageInfo<AttHystBase> pageInfo = new PageInfo(list);
- return pageInfo;
- }
- @Override
- public List<String> impExcelTest(MultipartFile file, AttHystBaseParam attHystBaseParam) {
- List<Row> rowList = ExportUtil.getRowListByFile(file);
- List<AttHystBase> addList = new ArrayList<>();
- List<AttHystBase> updateList = new ArrayList<>();
- if (rowList.size() > 1) {
- Row titleRow = rowList.get(0);//第一行标题
- for (int i = 1; i < rowList.size(); i++) {
- Row row = rowList.get(i);
- AttHystBase hystBaseParam = new AttHystBase();
- for (int j = 2; j < titleRow.getPhysicalNumberOfCells(); j++) {
- Cell cell = row.getCell(j);
- if (cell == null) {
- continue;
- }
- String value = cell.toString();
- if (StringUtils.isBlank(value)) {
- continue;
- }
- if (j == 2) {
- hystBaseParam.setHystName(value);
- } else if (j == 3) {
- hystBaseParam.setStatisCode(value);
- } else if (j == 5) {
- hystBaseParam.setAdCode(value);//存市
- } else if (j == 6) {
- hystBaseParam.setAdName(value);//存县
- } else if (j == 7) {
- hystBaseParam.setHystSite(value);//所在乡村
- } else if (j == 8) {
- hystBaseParam.setLinkMan(value);
- } else if (j == 9) {
- hystBaseParam.setLinkTel(value);
- } else if (j == 22) {//厂房所在河流域
- hystBaseParam.setRvName(value);
- } else if (j == 23) {//建设年月
- hystBaseParam.setCompDate(value);
- } else if (j == 24) {//所有制
- hystBaseParam.setOwnerType(value);
- } else if (j == 25) {//开发方式
- hystBaseParam.setExptType(value);
- } else if (j == 26) {//装机(kW)
- hystBaseParam.setInsCap(value);
- } else if (j == 27) {//坝高
- hystBaseParam.setDamHeig(value);
- } else if (j == 28) {//库容
- hystBaseParam.setTotCap(value);
- } else if (j == 29) {//生态流量核定值
- if (!value.equals("-")) {
- hystBaseParam.setZlgyFlow(value);
- }
- } else if (j == 30) {//水库是否注册
- hystBaseParam.setHystIsReg(value);
- } else if (j == 31) {//注册号
- hystBaseParam.setRegNo(value);
- } else if (j == 32) {//大坝是否开展安全鉴定
- hystBaseParam.setIsSafety(value);
- } else if (j == 33) {//清理整改分类
- hystBaseParam.setExmnType(value);
- } else if (j == 34) {//在建
- } else if (j == 35) {//厂房经度
- hystBaseParam.setHystLong(getFormateDouble(value));
- } else if (j == 36) {
- hystBaseParam.setHystLat(getFormateDouble(value));
- } else if (j == 37) {//取水经度
- hystBaseParam.setCenterX(getFormateDouble(value));
- } else if (j == 38) {
- hystBaseParam.setCenterY(getFormateDouble(value));
- }
- }
- if (StringUtils.isBlank(hystBaseParam.getId())) {
- hystBaseParam.setId(UuidUtil.uuid());
- hystBaseParam.setIntm(new Date());
- hystBaseParam.setUptm(new Date());
- addList.add(hystBaseParam);
- } else{
- updateList.add(hystBaseParam);
- }
- }
- }
- for (AttHystBase hystBaseParam : addList) {
- hystBaseParam.setOwnerType(getOwnerType(hystBaseParam.getOwnerType()));
- hystBaseParam.setExptType(getExptType(hystBaseParam.getExptType()));
- hystBaseParam.setHystIsReg(getShiFou(hystBaseParam.getHystIsReg()));
- hystBaseParam.setIsSafety(getIsSafety(hystBaseParam.getIsSafety()));
- hystBaseParam.setExmnType(getExmnType(hystBaseParam.getExmnType()));
- //处理行政区划
- AttAdXBaseParam attAdXBaseParam = new AttAdXBaseParam();
- attAdXBaseParam.setAdName(hystBaseParam.getAdName());
- attAdXBaseParam.setUpAdName(hystBaseParam.getAdCode());
- AttAdXBase by = attAdXBaseDao.getBy(attAdXBaseParam);
- if(by != null){
- hystBaseParam.setAdName(by.getAdName());
- hystBaseParam.setAdCode(by.getAdCode());
- }else{
- hystBaseParam.setAdCode("");
- }
- }
- if (addList.size() > 0) {
- for (AttHystBase wintBaseB : addList) {
- if (wintBaseB.getHystName() == null) {
- continue;
- }
- attHystBaseDao.insert(wintBaseB);
- }
- }
- if (updateList.size() > 0) {
- for (AttHystBase wintBaseB : updateList) {
- if (wintBaseB.getHystName() == null) {
- continue;
- }
- attHystBaseDao.update(wintBaseB);
- }
- }
- return null;
- }
- @Override
- public List<String> impExcelTestXY(MultipartFile file, AttHystBaseParam attHystBaseParam) {
- List<Row> rowList = ExportUtil.getRowListByFile(file);
- List<AttHystBase> addList = new ArrayList<>();
- List<AttHystBase> updateList = new ArrayList<>();
- if (rowList.size() > 1) {
- Row titleRow = rowList.get(0);//第一行标题
- for (int i = 1; i < rowList.size(); i++) {
- Row row = rowList.get(i);
- AttHystBase hystBaseParam = new AttHystBase();
- for (int j = 2; j < titleRow.getPhysicalNumberOfCells(); j++) {
- Cell cell = row.getCell(j);
- if (cell == null) {
- continue;
- }
- String value = cell.toString();
- if (StringUtils.isBlank(value)) {
- continue;
- }
- if (j == 2) {//名字
- hystBaseParam.setHystName(value);
- } else if (j == 3) {//统计代码
- hystBaseParam.setStatisCode(value);
- } else if(j == 33){//清理整改分类
- hystBaseParam.setExmnType(value);
- } else if (j == 35) {//厂房经度
- hystBaseParam.setHystLong(getFormateDouble(value));
- } else if (j == 36) {
- hystBaseParam.setHystLat(getFormateDouble(value));
- } else if (j == 37) {//取水经度
- hystBaseParam.setCenterX(getFormateDouble(value));
- } else if (j == 38) {
- hystBaseParam.setCenterY(getFormateDouble(value));
- }
- }
- updateList.add(hystBaseParam);
- }
- }
- if(updateList.size()>0){
- for (AttHystBase attHystBase : updateList) {
- //获取水电站
- AttHystBaseParam attParam = new AttHystBaseParam();
- attParam.setHystName(attHystBase.getHystName());
- attParam.setStatisCode(attHystBase.getStatisCode());
- AttHystBase by = attHystBaseDao.getBy(attParam);
- AttHystBase newB = new AttHystBase();
- if(by != null){
- newB.setId(by.getId());
- newB.setHystLong(attHystBase.getHystLong());
- newB.setHystLat(attHystBase.getHystLat());
- // by.setCenterX(attHystBase.getCenterX());
- // by.setCenterY(attHystBase.getCenterY());
- String exmnType = getExmnType(attParam.getExmnType());
- if(by.getExmnType()==null || !by.getExmnType().equals(exmnType)){
- by.setExmnType(exmnType);
- }
- addList.add(newB);
- }
- }
- }
- if(addList.size()>0){
- for (AttHystBase base : addList) {
- attHystBaseDao.update(base);
- }
- }
- return null;
- }
- @Override
- public List<String> uploadComp(MultipartFile file, AttHystBaseParam attBaseBParam) {
- List<Row> rowList = ExportUtil.getRowListByFile(file);
- List<AttHystBase> result = new ArrayList<>();
- if (rowList.size() > 1) {
- Row titleRow = rowList.get(0);//第一行标题
- for (int i = 1; i < rowList.size(); i++) {
- Row row = rowList.get(i);
- AttHystBase base = new AttHystBase();
- for (int j = 0; j < titleRow.getPhysicalNumberOfCells(); j++) {
- Cell cell = row.getCell(j);
- if (cell == null) {
- continue;
- }
- String value = cell.toString();
- if (StringUtils.isBlank(value)) {
- continue;
- }
- if (j == 0) {
- base.setHystName(value);
- } else if (j == 1) {
- if (value.equals("-")) {
- } else {
- base.setStatisCode(value);
- }
- } else if (j == 2) {
- base.setCompDate(value);
- }
- }
- result.add(base);
- }
- if (result.size() > 0) {
- for (AttHystBase base : result) {
- attHystBaseDao.updateBase(base);
- }
- }
- }
- return null;
- }
- @Override
- public List<String> upload(MultipartFile file, AttHystBaseParam attBaseBParam) {
- List<Row> rowList = ExportUtil.getRowListByFile(file);
- List<AttHystBase> result = new ArrayList<>();
- if (rowList.size() > 1) {
- Row titleRow = rowList.get(0);//第一行标题
- for (int i = 1; i < rowList.size(); i++) {
- Row row = rowList.get(i);
- AttHystBase base = new AttHystBase();
- for (int j = 2; j < titleRow.getPhysicalNumberOfCells(); j++) {
- Cell cell = row.getCell(j);
- if (cell == null) {
- continue;
- }
- String value = cell.toString();
- if (StringUtils.isBlank(value)) {
- continue;
- }
- if (j == 2) {
- base.setHystName(value);
- } else if (j == 3) {//统计代码
- base.setStatisCode(value);
- } else if (j == 4) {
- base.setAdName(value);
- } else if (j == 5) {
- base.setHystSite(value);
- } else if (j == 6) {
- base.setLinkMan(value);
- } else if (j == 7) {
- base.setLinkTel(value);
- } else if (j == 8) {
- base.setHystLong(Double.valueOf(value));
- } else if (j == 9) {
- base.setHystLong(Double.valueOf(value) + base.getHystLong()/60);
- } else if (j == 10){
- base.setHystLong(Double.valueOf(value) + base.getHystLong()/60);
- } else if (j == 11) {
- base.setHystLat(Double.valueOf(value));
- } else if (j == 12){
- base.setHystLat(Double.valueOf(value) + base.getHystLat()/60);
- } else if (j == 13) {
- base.setHystLat(Double.valueOf(value) + base.getHystLat()/60);
- } else if (j == 14) {
- base.setCenterX(Double.valueOf(value));
- } else if (j == 15) {
- base.setCenterX(Double.valueOf(value) + base.getCenterX()/60);
- } else if (j == 16){
- base.setCenterX(Double.valueOf(value) + base.getCenterX()/60);
- } else if (j == 17) {
- base.setCenterY(Double.valueOf(value));
- } else if (j == 18) {
- base.setCenterY(Double.valueOf(value) + base.getCenterY()/60);
- } else if (j == 19){
- base.setCenterY(Double.valueOf(value) + base.getCenterY()/60);
- } else if (j == 20) {
- base.setRvName(value);
- } else if (j == 21) {
- base.setCompDate(Double.valueOf(value).longValue()+"");
- } else if (j == 22) {
- base.setOwnerType(getOwnerType(value));
- } else if (j == 23) {
- base.setExptType(getExptType(value));
- } else if (j == 24) {
- base.setInsCap(value);
- } else if (j == 25) {
- base.setDamHeig(value);
- } else if (j == 26) {
- base.setTotCap(value);
- } else if (j == 27) {
- base.setZlgyFlow(value);
- } else if (j == 28) {
- base.setHystIsReg(getShiFou(value));
- } else if (j == 29) {
- base.setRegNo(value);
- } else if (j == 30) {
- base.setIsSafety(getIsSafety(value));
- } else if (j == 31) {
- base.setExmnType(getExmnType(value));
- }
- }
- if (StringUtils.isBlank(base.getHystName())) {
- continue;
- }
- result.add(base);
- }
- }
- if (result.size() >0) {
- Map<String,String> map = new HashMap<>();
- for (AttHystBase base : result) {
- base.setId(UuidUtil.uuid());
- base.setIntm(new Date());
- base.setUptm(new Date());
- if (map.containsKey(base.getAdName())) {
- base.setAdCode(map.get(base.getAdName()));
- }
- //处理行政区划
- AttAdXBaseParam attAdXBaseParam = new AttAdXBaseParam();
- attAdXBaseParam.setAdName(base.getAdName());
- List<AttAdXBase> by = attAdXBaseDao.findList(attAdXBaseParam);
- if(by.size() > 0) {
- base.setAdCode(by.get(0).getAdCode());
- map.put(base.getAdName(),by.get(0).getAdCode());
- }
- attHystBaseDao.insert(base);
- }
- }
- return null;
- }
- private Double getFormateDouble(String s){
- if(s ==null || s.equals("0")){
- return 0.0;
- }else {
- // String format1 = String.format("%.8f", s);
- // return Double.valueOf(format1);
- // DecimalFormat df = new DecimalFormat("0.00000000");
- // String format = df.format(s);
- double d = Double.valueOf(s);
- return (double) Math.round(d * 100000000) / 100000000;
- }
- }
- private String getOwnerType(String s){
- //(1:民营;2:集体;3:国有;4:股份制;)
- if(s == null){ return s;}
- if(s.equals("民营")){
- return "1";
- }else if(s.equals("集体")){
- return "2";
- }else if(s.equals("国有")){
- return "3";
- }else if(s.equals("股份制")){
- return "4";
- }else if(s.equals("其他")){
- return "5";
- }else if(s.equals("-")){
- return "";
- }
- return "6";
- }
- private String getExptType(String s){
- //((1:引水式;2:混合式;3:坝后式;4:河床式;5:其他-工农业渠道上;6:其他-接上一级尾水)
- if(s == null){ return s;}
- if(s.equals("引水式")){
- return "1";
- }else if(s.equals("混合式")){
- return "2";
- }else if(s.equals("坝后式") || s.equals("坝式(坝后)")){
- return "3";
- }else if(s.equals("河床式") ||s.equals("坝式(河床)")){
- return "4";
- }else if(s.equals("其他-工农业渠道上")){
- return "5";
- }else if(s.equals("其他-接上一级尾水")){
- return "6";
- }else if(s.equals("-")){
- return "";
- }
- return "6";
- }
- private String getShiFou(String s){
- if(s == null){ return s;}
- //(1:是;2:否;)
- if(s.equals("是")){
- return "1";
- }else if(s.equals("否")){
- return "2";
- }else if(s.equals("-")){
- return "";
- }
- return s;
- }
- private String getIsSafety(String s){
- if(s == null){ return s;}
- //(1:是;2:否;)
- if(s.equals("是")|| s.equals("是,二类")
- || s.equals("是,一类")|| s.equals("是,三类")){
- return "1";
- }else if(s.equals("否")){
- return "2";
- }else if(s.equals("-")){
- return "";
- }
- return "3";
- }
- private String getExmnType(String s){
- //1:整改类;2:立即退出类;3:其他;4:保留类5.
- if(s ==null || s.equals("")){
- return "3";
- }
- if(s.equals("整改")){
- return "1";
- }else if(s.equals("立即退出")){
- return "2";
- }else if(s.equals("")){
- return "3";
- }else if(s.equals("保留")){
- return "4";
- }else if(s.equals("限期退出")){
- return "5";
- }else if(s.equals("-")){
- return "";
- }
- return "6";
- }
- }
|