|
|
@@ -3,22 +3,20 @@ package jp.yamoto.farm.crm.biz.master.service.impl;
|
|
|
import jp.yamoto.farm.common.core.domain.model.LoginUser;
|
|
|
import jp.yamoto.farm.common.core.enums.DelFlgEnum;
|
|
|
import jp.yamoto.farm.common.exception.ServiceException;
|
|
|
-import jp.yamoto.farm.common.utils.MessageUtils;
|
|
|
-import jp.yamoto.farm.common.utils.SecurityUtils;
|
|
|
-import jp.yamoto.farm.common.utils.ValueUtils;
|
|
|
+import jp.yamoto.farm.common.utils.*;
|
|
|
import jp.yamoto.farm.common.utils.uuid.IdUtils;
|
|
|
import jp.yamoto.farm.crm.biz.master.domain.bo.MastFarmerBo;
|
|
|
import jp.yamoto.farm.crm.biz.master.domain.entity.MastFarmer;
|
|
|
import jp.yamoto.farm.crm.biz.master.domain.vo.MastFarmerVo;
|
|
|
import jp.yamoto.farm.crm.biz.master.mapper.MastFarmerMapper;
|
|
|
import jp.yamoto.farm.crm.biz.master.service.IMastFarmerService;
|
|
|
+import lombok.SneakyThrows;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import jp.yamoto.farm.common.utils.DateUtils;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
@@ -40,16 +38,15 @@ public class MastFarmerServiceImpl implements IMastFarmerService {
|
|
|
*/
|
|
|
@Override
|
|
|
public MastFarmerVo selectById(String id) {
|
|
|
- MastFarmer mastFarmer = mastFarmerMapper.selectById(id);
|
|
|
+ MastFarmerVo mastFarmerVo = mastFarmerMapper.selectById(id);
|
|
|
|
|
|
- if (mastFarmer == null) {
|
|
|
+ if (mastFarmerVo == null) {
|
|
|
throw new ServiceException(MessageUtils.message("E0007"));
|
|
|
}
|
|
|
- MastFarmerVo item = new MastFarmerVo();
|
|
|
- BeanUtils.copyProperties(mastFarmer, item);
|
|
|
- // デコードページにはアイテムが表示されます
|
|
|
- this.deEncodingPageItems(item);
|
|
|
- return item;
|
|
|
+
|
|
|
+ // 検索結果をリセット
|
|
|
+ this.restSearchData4View(mastFarmerVo);
|
|
|
+ return mastFarmerVo;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -66,31 +63,48 @@ public class MastFarmerServiceImpl implements IMastFarmerService {
|
|
|
BeanUtils.copyProperties(mastFarmerBo, mastFarmer);
|
|
|
// エリによってリストが返されました。
|
|
|
List<MastFarmerVo> farmerLst = mastFarmerMapper.selectList(mastFarmer);
|
|
|
- farmerLst.forEach(p->{
|
|
|
- this.deEncodingPageItems(p);
|
|
|
- });
|
|
|
+ for (MastFarmerVo p : farmerLst) {
|
|
|
+ this.restSearchData4View(p);
|
|
|
+ }
|
|
|
return farmerLst;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 農家マスタの追加
|
|
|
+ * 農家マスタの保存
|
|
|
*
|
|
|
* @param mastFarmerBo 農家マスタパラメータ対象
|
|
|
* @return 結果
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public int insert(MastFarmerBo mastFarmerBo) {
|
|
|
+ public int save(MastFarmerBo mastFarmerBo) {
|
|
|
+
|
|
|
+ if (ValueUtils.isEmpty(mastFarmerBo.getId())) {
|
|
|
+ // 農家マスタの追加
|
|
|
+ return this.insert(mastFarmerBo);
|
|
|
+ } else {
|
|
|
+ // 農家マスタの編集
|
|
|
+ return this.update(mastFarmerBo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 農家マスタの追加
|
|
|
+ *
|
|
|
+ * @param mastFarmerBo 農家マスタパラメータ対象
|
|
|
+ * @return 結果
|
|
|
+ */
|
|
|
+ private int insert(MastFarmerBo mastFarmerBo) {
|
|
|
MastFarmer mastFarmer = new MastFarmer();
|
|
|
BeanUtils.copyProperties(mastFarmerBo, mastFarmer);
|
|
|
|
|
|
// その他の情報を構築します。
|
|
|
- this.buildMastFarmerInfo(mastFarmer);
|
|
|
+ this.buildFarmerInfo4Save(mastFarmer);
|
|
|
|
|
|
// 農家IDの重複チェック
|
|
|
int mastFarmerCount = mastFarmerMapper.getFarmerIdCount(mastFarmerBo.getFarmerId());
|
|
|
if (mastFarmerCount > 0) {
|
|
|
- throw new ServiceException(MessageUtils.message("E0001", MessageUtils.message("label.nokaCd")));
|
|
|
+ throw new ServiceException(MessageUtils.message("E0001", MessageUtils.message("label.farmerId")));
|
|
|
}
|
|
|
|
|
|
return mastFarmerMapper.insert(mastFarmer);
|
|
|
@@ -102,13 +116,11 @@ public class MastFarmerServiceImpl implements IMastFarmerService {
|
|
|
* @param mastFarmerBo 農家マスタパラメータ対象
|
|
|
* @return 結果
|
|
|
*/
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public int update(MastFarmerBo mastFarmerBo) {
|
|
|
+ private int update(MastFarmerBo mastFarmerBo) {
|
|
|
MastFarmer mastFarmer = new MastFarmer();
|
|
|
BeanUtils.copyProperties(mastFarmerBo, mastFarmer);
|
|
|
// その他の情報を構築します。
|
|
|
- this.buildMastFarmerInfo(mastFarmer);
|
|
|
+ this.buildFarmerInfo4Save(mastFarmer);
|
|
|
|
|
|
int result = mastFarmerMapper.update(mastFarmer);
|
|
|
if (result < 1) {
|
|
|
@@ -139,11 +151,11 @@ public class MastFarmerServiceImpl implements IMastFarmerService {
|
|
|
*
|
|
|
* @param mastFarmer 農家マスタ情報
|
|
|
*/
|
|
|
- private void buildMastFarmerInfo(MastFarmer mastFarmer) {
|
|
|
+ private void buildFarmerInfo4Save(MastFarmer mastFarmer) {
|
|
|
// ログインユーザー情報を取得します
|
|
|
LoginUser loginUser = SecurityUtils.getLoginUser();
|
|
|
// ID が空の場合は、ID を設定します。
|
|
|
- if(ValueUtils.isEmpty(mastFarmer.getId())) {
|
|
|
+ if (ValueUtils.isEmpty(mastFarmer.getId())) {
|
|
|
// ID
|
|
|
mastFarmer.setId(IdUtils.nextIdStr());
|
|
|
// 発行者
|
|
|
@@ -151,6 +163,9 @@ public class MastFarmerServiceImpl implements IMastFarmerService {
|
|
|
// 発行日
|
|
|
mastFarmer.setIssuedDate(DateUtils.getDate());
|
|
|
}
|
|
|
+
|
|
|
+ // データを暗号化
|
|
|
+ // パスワード
|
|
|
if (mastFarmer.getUserPassword() != null && !mastFarmer.getUserPassword().isEmpty()) {
|
|
|
mastFarmer.setUserPassword(SecurityUtils.encryptPassword(mastFarmer.getUserPassword()));
|
|
|
}
|
|
|
@@ -161,18 +176,27 @@ public class MastFarmerServiceImpl implements IMastFarmerService {
|
|
|
|
|
|
// メールアドレス
|
|
|
if (ValueUtils.isNotEmpty(mastFarmer.getMailAddress())) {
|
|
|
- mastFarmer.setMailAddress(SecurityUtils.encryptPassword(mastFarmer.getMailAddress()));
|
|
|
+// mastFarmer.setMailAddress(DecryptUtils.encryptAES(mastFarmer.getMailAddress()));
|
|
|
+ }
|
|
|
+ // 電話番号
|
|
|
+ if (ValueUtils.isNotEmpty(mastFarmer.getMailAddress())) {
|
|
|
+// mastFarmer.setPhoneNumber(DecryptUtils.encryptAES(mastFarmer.getPhoneNumber()));
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * デコードページにはアイテムが表示されます
|
|
|
+ * 検索結果をリセット
|
|
|
*
|
|
|
- * @param mastFarmer 農家マスタ情報
|
|
|
+ * @param mastFarmerVo 農家マスタ詳細情報Vo
|
|
|
*/
|
|
|
- private void deEncodingPageItems(MastFarmerVo mastFarmer) {
|
|
|
+ @SneakyThrows
|
|
|
+ private void restSearchData4View(MastFarmerVo mastFarmerVo) {
|
|
|
+ // デコードページにはアイテムが表示されます
|
|
|
|
|
|
+ // 電話番号
|
|
|
+// String PhoneNumber = DecryptUtils.decryptAES(mastFarmerVo.getPhoneNumber());
|
|
|
+// mastFarmerVo.setPhoneNumber(PhoneNumber);
|
|
|
}
|
|
|
|
|
|
}
|